forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define OSCompat module (facebook#49302)
Summary: # Changelog: [Internal] Added OS-agnostic module that will implement 2 basic capabilities: - Getting current process id - Getting current thread id Reviewed By: javache Differential Revision: D69316093
- Loading branch information
1 parent
1b066ba
commit 6e1e52d
Showing
9 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
cmake_minimum_required(VERSION 3.13) | ||
set(CMAKE_VERBOSE_MAKEFILE on) | ||
|
||
add_compile_options(-fexceptions) | ||
|
||
file(GLOB oscompat_SRC CONFIGURE_DEPENDS *.cpp) | ||
add_library(oscompat OBJECT ${oscompat_SRC}) | ||
|
||
target_include_directories(oscompat PUBLIC .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
namespace facebook::react::oscompat { | ||
|
||
uint64_t getCurrentProcessId(); | ||
|
||
uint64_t getCurrentThreadId(); | ||
|
||
} // namespace facebook::react::oscompat |
63 changes: 63 additions & 0 deletions
63
packages/react-native/ReactCommon/oscompat/OSCompatPosix.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || \ | ||
defined(__ANDROID__) | ||
|
||
#include "OSCompat.h" | ||
|
||
#include <cassert> | ||
|
||
#include <pthread.h> | ||
#include <unistd.h> | ||
|
||
#if defined(__MACH__) | ||
#include <mach/mach.h> | ||
#endif // defined(__MACH__) | ||
|
||
#if defined(__linux__) | ||
#include <sys/syscall.h> | ||
#endif // defined(__linux__) | ||
|
||
namespace facebook::react::oscompat { | ||
|
||
uint64_t getCurrentProcessId() { | ||
return getpid(); | ||
} | ||
|
||
#if defined(__APPLE__) && defined(__MACH__) | ||
|
||
uint64_t getCurrentThreadId() { | ||
uint64_t tid = 0; | ||
auto ret = pthread_threadid_np(nullptr, &tid); | ||
assert( | ||
ret == 0 && | ||
"Unexpected pthread_threadid_np failure while getting thread ID"); | ||
(void)ret; | ||
return tid; | ||
} | ||
|
||
#elif defined(__ANDROID__) | ||
|
||
uint64_t getCurrentThreadId() { | ||
return gettid(); | ||
} | ||
|
||
#elif defined(__linux__) | ||
|
||
uint64_t getCurrentThreadId() { | ||
return syscall(__NR_gettid); | ||
} | ||
|
||
#else | ||
#error "getCurrentThreadID() is not supported on this platform" | ||
#endif | ||
|
||
} // namespace facebook::react::oscompat | ||
|
||
#endif // defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || | ||
// defined(__ANDROID__) |
26 changes: 26 additions & 0 deletions
26
packages/react-native/ReactCommon/oscompat/OSCompatWindows.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#if defined(_WIN32) || defined(_MSC_VER) | ||
|
||
#include "OSCompat.h" | ||
|
||
#include <windows.h> | ||
|
||
namespace facebook::react::oscompat { | ||
|
||
uint64_t getCurrentProcessId() { | ||
return GetCurrentProcessId(); | ||
} | ||
|
||
uint64_t getCurrentThreadId() { | ||
return GetCurrentThreadId(); | ||
} | ||
|
||
} // namespace facebook::react::oscompat | ||
|
||
#endif // defined(_WIN32) || defined(_MSC_VER) |
31 changes: 31 additions & 0 deletions
31
packages/react-native/ReactCommon/oscompat/React-oscompat.podspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
require "json" | ||
|
||
package = JSON.parse(File.read(File.join(__dir__, "..", "..", "package.json"))) | ||
version = package['version'] | ||
|
||
source = { :git => 'https://github.com/facebook/react-native.git' } | ||
if version == '1000.0.0' | ||
# This is an unpublished version, use the latest commit hash of the react-native repo, which we’re presumably in. | ||
source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1") | ||
else | ||
source[:tag] = "v#{version}" | ||
end | ||
|
||
Pod::Spec.new do |s| | ||
s.name = "React-oscompat" | ||
s.version = version | ||
s.summary = "Small set of OS-level utilities for React Native" | ||
s.homepage = "https://reactnative.dev/" | ||
s.license = package["license"] | ||
s.author = "Meta Platforms, Inc. and its affiliates" | ||
s.platforms = min_supported_versions | ||
s.source = source | ||
s.source_files = "*.{cpp,h}" | ||
s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "" } | ||
s.header_dir = "oscompat" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters