summaryrefslogtreecommitdiffstats
path: root/libcutils
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2015-03-20 13:46:28 -0700
committerDan Albert <danalbert@google.com>2015-03-23 13:01:21 -0700
commit7dfb61dcdca8ee597f23b9acc365fb140b353fff (patch)
tree9a4f01224517df3b3467d8cf4cd77a10bfffc3d8 /libcutils
parenta5e9639cf94aad0ed88ccd1c08d43f5084432f74 (diff)
downloadsystem_core-7dfb61dcdca8ee597f23b9acc365fb140b353fff.tar.gz
system_core-7dfb61dcdca8ee597f23b9acc365fb140b353fff.tar.bz2
system_core-7dfb61dcdca8ee597f23b9acc365fb140b353fff.zip
Move gettid() into libcutils.
Change-Id: Ic8a15036833e6d129b7998d954b804be391de399
Diffstat (limited to 'libcutils')
-rw-r--r--libcutils/threads.c31
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 @@
** limitations under the License.
*/
-#include <cutils/threads.h>
+#include "cutils/threads.h"
#if !defined(_WIN32)
+
+// For gettid.
+#if defined(__APPLE__)
+#include "AvailabilityMacros.h" // For MAC_OS_X_VERSION_MAX_ALLOWED
+#include <sys/syscall.h>
+#include <sys/time.h>
+#include "base/logging.h"
+#elif defined(__linux__) && !defined(__ANDROID__)
+#include <syscall.h>
+#include <unistd.h>
+#elif defined(_WIN32)
+#include <Windows.h>
+#endif
+
void* thread_store_get( thread_store_t* store )
{
if (!store->has_tls)
@@ -42,6 +56,21 @@ extern void thread_store_set( thread_store_t* store,
pthread_setspecific( store->tls, value );
}
+// No definition needed for Android because we'll just pick up bionic's copy.
+#ifndef __ANDROID__
+pid_t gettid() {
+#if defined(__APPLE__)
+ uint64_t owner;
+ CHECK_PTHREAD_CALL(pthread_threadid_np, (NULL, &owner), __FUNCTION__);
+ return owner;
+#elif defined(__linux__)
+ return syscall(__NR_gettid);
+#elif defined(_WIN32)
+ return (pid_t)GetCurrentThreadId();
+#endif
+}
+#endif // __ANDROID__
+
#else /* !defined(_WIN32) */
void* thread_store_get( thread_store_t* store )
{