Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/ThreadingPthreads.cpp |
| diff --git a/third_party/WebKit/Source/wtf/ThreadingPthreads.cpp b/third_party/WebKit/Source/wtf/ThreadingPthreads.cpp |
| index 49a35eb33906c2ab6863979184258aeec1721f92..ad9b520ac9f44add1284c67ea911ffe9aed00030 100644 |
| --- a/third_party/WebKit/Source/wtf/ThreadingPthreads.cpp |
| +++ b/third_party/WebKit/Source/wtf/ThreadingPthreads.cpp |
| @@ -59,6 +59,22 @@ |
| namespace WTF { |
| +namespace internal { |
| + |
| +ThreadIdentifier currentThreadSyscall() { |
| +#if OS(MACOSX) |
| + return pthread_mach_thread_np(pthread_self()); |
| +#elif OS(LINUX) |
| + return syscall(__NR_gettid); |
| +#elif OS(ANDROID) |
| + return gettid(); |
| +#else |
| + return reinterpret_cast<uintptr_t>(pthread_self()); |
| +#endif |
| +} |
| + |
| +} // namespace internal |
| + |
| static Mutex* atomicallyInitializedStaticMutex; |
| void initializeThreading() { |
| @@ -87,14 +103,14 @@ void unlockAtomicallyInitializedStaticMutex() { |
| } |
| ThreadIdentifier currentThread() { |
| -#if OS(MACOSX) |
| - return pthread_mach_thread_np(pthread_self()); |
| -#elif OS(LINUX) |
| - return syscall(__NR_gettid); |
| -#elif OS(ANDROID) |
| - return gettid(); |
| +// TLS lookup is fast on these platforms. |
|
haraken
2017/01/13 04:36:07
Have you confirmed that TLS lookup is fast on Mac
Charlie Harrison
2017/01/13 16:38:45
I don't think __GLIBC__ is enabled on mac, and thi
|
| +#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) |
| + return wtfThreadData().threadId(); |
| #else |
|
haraken
2017/01/13 04:33:43
On what platform do we hit this #else block? I thi
Charlie Harrison
2017/01/13 16:38:44
I think just Mac
|
| - return reinterpret_cast<uintptr_t>(pthread_self()); |
| + // TODO(csharrison): For platforms where TLS lookup is slow, use the hack that |
| + // oilpan uses in ThreadState::current() to check if this is the main thread |
| + // via stack address. |
| + return internal::currentThreadSyscall(); |
| #endif |
| } |