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 85a3976090948bb06a944969aa7b771ef9d023f1..b86de9b1763553a01d2a9a91701e5a5f5e12602e 100644 |
| --- a/third_party/WebKit/Source/wtf/ThreadingPthreads.cpp |
| +++ b/third_party/WebKit/Source/wtf/ThreadingPthreads.cpp |
| @@ -85,8 +85,29 @@ void initializeThreading() { |
| double_conversion::DoubleToStringConverter::EcmaScriptConverter(); |
| } |
| +namespace { |
| +ThreadSpecificKey s_currentThreadKey; |
| +bool s_currentThreadKeyInitialized = false; |
| +} // namespace |
| + |
| +void initializeCurrentThread() { |
| + DCHECK(!s_currentThreadKeyInitialized); |
| + threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {}); |
| + s_currentThreadKeyInitialized = true; |
| +} |
| + |
| ThreadIdentifier currentThread() { |
| - return wtfThreadData().threadId(); |
|
haraken
2017/03/06 19:21:36
A stupid question: Why can't we use wtfThreadData(
jbroman
2017/03/06 20:28:09
Cyclic dependency. If wtfThreadData() is used here
haraken
2017/03/06 20:46:42
Ah, got it. Maybe it's worth having a comment :)
jbroman
2017/03/07 16:03:30
Done.
|
| + static_assert(sizeof(ThreadIdentifier) <= sizeof(void*), |
| + "ThreadIdentifier must fit in a void*."); |
| + DCHECK(s_currentThreadKeyInitialized); |
| + void* value = threadSpecificGet(s_currentThreadKey); |
| + if (UNLIKELY(!value)) { |
| + value = reinterpret_cast<void*>( |
| + static_cast<intptr_t>(internal::currentThreadSyscall())); |
| + DCHECK(value); |
| + threadSpecificSet(s_currentThreadKey, value); |
| + } |
| + return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey)); |
| } |
| MutexBase::MutexBase(bool recursive) { |