diff options
author | Dan Albert | 2015-03-20 15:46:28 -0500 |
---|---|---|
committer | Dan Albert | 2015-03-23 15:01:21 -0500 |
commit | 7dfb61dcdca8ee597f23b9acc365fb140b353fff (patch) | |
tree | 9a4f01224517df3b3467d8cf4cd77a10bfffc3d8 /libcutils/threads.c | |
parent | a5e9639cf94aad0ed88ccd1c08d43f5084432f74 (diff) | |
download | platform-system-core-7dfb61dcdca8ee597f23b9acc365fb140b353fff.tar.gz platform-system-core-7dfb61dcdca8ee597f23b9acc365fb140b353fff.tar.xz platform-system-core-7dfb61dcdca8ee597f23b9acc365fb140b353fff.zip |
Move gettid() into libcutils.
Change-Id: Ic8a15036833e6d129b7998d954b804be391de399
Diffstat (limited to 'libcutils/threads.c')
-rw-r--r-- | libcutils/threads.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/libcutils/threads.c b/libcutils/threads.c index ca600b3b1..cafeff73f 100644 --- a/libcutils/threads.c +++ b/libcutils/threads.c | |||
@@ -14,9 +14,23 @@ | |||
14 | ** limitations under the License. | 14 | ** limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <cutils/threads.h> | 17 | #include "cutils/threads.h" |
18 | 18 | ||
19 | #if !defined(_WIN32) | 19 | #if !defined(_WIN32) |
20 | |||
21 | // For gettid. | ||
22 | #if defined(__APPLE__) | ||
23 | #include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED | ||
24 | #include <sys/syscall.h> | ||
25 | #include <sys/time.h> | ||
26 | #include "base/logging.h" | ||
27 | #elif defined(__linux__) && !defined(__ANDROID__) | ||
28 | #include <syscall.h> | ||
29 | #include <unistd.h> | ||
30 | #elif defined(_WIN32) | ||
31 | #include <Windows.h> | ||
32 | #endif | ||
33 | |||
20 | void* thread_store_get( thread_store_t* store ) | 34 | void* thread_store_get( thread_store_t* store ) |
21 | { | 35 | { |
22 | if (!store->has_tls) | 36 | if (!store->has_tls) |
@@ -42,6 +56,21 @@ extern void thread_store_set( thread_store_t* store, | |||
42 | pthread_setspecific( store->tls, value ); | 56 | pthread_setspecific( store->tls, value ); |
43 | } | 57 | } |
44 | 58 | ||
59 | // No definition needed for Android because we'll just pick up bionic's copy. | ||
60 | #ifndef __ANDROID__ | ||
61 | pid_t gettid() { | ||
62 | #if defined(__APPLE__) | ||
63 | uint64_t owner; | ||
64 | CHECK_PTHREAD_CALL(pthread_threadid_np, (NULL, &owner), __FUNCTION__); | ||
65 | return owner; | ||
66 | #elif defined(__linux__) | ||
67 | return syscall(__NR_gettid); | ||
68 | #elif defined(_WIN32) | ||
69 | return (pid_t)GetCurrentThreadId(); | ||
70 | #endif | ||
71 | } | ||
72 | #endif // __ANDROID__ | ||
73 | |||
45 | #else /* !defined(_WIN32) */ | 74 | #else /* !defined(_WIN32) */ |
46 | void* thread_store_get( thread_store_t* store ) | 75 | void* thread_store_get( thread_store_t* store ) |
47 | { | 76 | { |