Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) |
| 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. | 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 void initializeThreading() { | 78 void initializeThreading() { |
| 79 // This should only be called once. | 79 // This should only be called once. |
| 80 WTFThreadData::initialize(); | 80 WTFThreadData::initialize(); |
| 81 | 81 |
| 82 initializeDates(); | 82 initializeDates(); |
| 83 // Force initialization of static DoubleToStringConverter converter variable | 83 // Force initialization of static DoubleToStringConverter converter variable |
| 84 // inside EcmaScriptConverter function while we are in single thread mode. | 84 // inside EcmaScriptConverter function while we are in single thread mode. |
| 85 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 85 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 namespace { | |
| 89 ThreadSpecificKey s_currentThreadKey; | |
| 90 bool s_currentThreadKeyInitialized = false; | |
| 91 } // namespace | |
| 92 | |
| 93 void initializeCurrentThread() { | |
| 94 DCHECK(!s_currentThreadKeyInitialized); | |
| 95 threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {}); | |
| 96 s_currentThreadKeyInitialized = true; | |
| 97 } | |
| 98 | |
| 88 ThreadIdentifier currentThread() { | 99 ThreadIdentifier currentThread() { |
| 89 return wtfThreadData().threadId(); | 100 static_assert(sizeof(ThreadIdentifier) <= sizeof(void*), |
|
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.
| |
| 101 "ThreadIdentifier must fit in a void*."); | |
| 102 DCHECK(s_currentThreadKeyInitialized); | |
| 103 void* value = threadSpecificGet(s_currentThreadKey); | |
| 104 if (UNLIKELY(!value)) { | |
| 105 value = reinterpret_cast<void*>( | |
| 106 static_cast<intptr_t>(internal::currentThreadSyscall())); | |
| 107 DCHECK(value); | |
| 108 threadSpecificSet(s_currentThreadKey, value); | |
| 109 } | |
| 110 return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey)); | |
| 90 } | 111 } |
| 91 | 112 |
| 92 MutexBase::MutexBase(bool recursive) { | 113 MutexBase::MutexBase(bool recursive) { |
| 93 pthread_mutexattr_t attr; | 114 pthread_mutexattr_t attr; |
| 94 pthread_mutexattr_init(&attr); | 115 pthread_mutexattr_init(&attr); |
| 95 pthread_mutexattr_settype( | 116 pthread_mutexattr_settype( |
| 96 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); | 117 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); |
| 97 | 118 |
| 98 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); | 119 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); |
| 99 DCHECK_EQ(result, 0); | 120 DCHECK_EQ(result, 0); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 245 } |
| 225 | 246 |
| 226 void willCreateThread() { | 247 void willCreateThread() { |
| 227 s_threadCreated = true; | 248 s_threadCreated = true; |
| 228 } | 249 } |
| 229 #endif | 250 #endif |
| 230 | 251 |
| 231 } // namespace WTF | 252 } // namespace WTF |
| 232 | 253 |
| 233 #endif // OS(POSIX) | 254 #endif // OS(POSIX) |
| OLD | NEW |