| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2009 Torch Mobile, Inc. All rights reserved. | 4 * Copyright (C) 2009 Torch Mobile, Inc. 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 void initializeThreading() { | 136 void initializeThreading() { |
| 137 // This should only be called once. | 137 // This should only be called once. |
| 138 WTFThreadData::initialize(); | 138 WTFThreadData::initialize(); |
| 139 | 139 |
| 140 initializeDates(); | 140 initializeDates(); |
| 141 // Force initialization of static DoubleToStringConverter converter variable | 141 // Force initialization of static DoubleToStringConverter converter variable |
| 142 // inside EcmaScriptConverter function while we are in single thread mode. | 142 // inside EcmaScriptConverter function while we are in single thread mode. |
| 143 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 143 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 namespace { |
| 147 ThreadSpecificKey s_currentThreadKey; |
| 148 bool s_currentThreadKeyInitialized = false; |
| 149 } // namespace |
| 150 |
| 151 void initializeCurrentThread() { |
| 152 DCHECK(!s_currentThreadKeyInitialized); |
| 153 threadSpecificKeyCreate(&s_currentThreadKey, [](void*) {}); |
| 154 s_currentThreadKeyInitialized = true; |
| 155 } |
| 156 |
| 146 ThreadIdentifier currentThread() { | 157 ThreadIdentifier currentThread() { |
| 147 return wtfThreadData().threadId(); | 158 // This doesn't use WTF::ThreadSpecific (e.g. WTFThreadData) because |
| 159 // ThreadSpecific now depends on currentThread. It is necessary to avoid this |
| 160 // or a similar loop: |
| 161 // |
| 162 // currentThread |
| 163 // -> wtfThreadData |
| 164 // -> ThreadSpecific::operator* |
| 165 // -> isMainThread |
| 166 // -> currentThread |
| 167 static_assert(sizeof(ThreadIdentifier) <= sizeof(void*), |
| 168 "ThreadIdentifier must fit in a void*."); |
| 169 DCHECK(s_currentThreadKeyInitialized); |
| 170 void* value = threadSpecificGet(s_currentThreadKey); |
| 171 if (UNLIKELY(!value)) { |
| 172 value = reinterpret_cast<void*>(internal::currentThreadSyscall()); |
| 173 DCHECK(value); |
| 174 threadSpecificSet(s_currentThreadKey, value); |
| 175 } |
| 176 return reinterpret_cast<intptr_t>(threadSpecificGet(s_currentThreadKey)); |
| 148 } | 177 } |
| 149 | 178 |
| 150 MutexBase::MutexBase(bool recursive) { | 179 MutexBase::MutexBase(bool recursive) { |
| 151 m_mutex.m_recursionCount = 0; | 180 m_mutex.m_recursionCount = 0; |
| 152 InitializeCriticalSection(&m_mutex.m_internalMutex); | 181 InitializeCriticalSection(&m_mutex.m_internalMutex); |
| 153 } | 182 } |
| 154 | 183 |
| 155 MutexBase::~MutexBase() { | 184 MutexBase::~MutexBase() { |
| 156 DeleteCriticalSection(&m_mutex.m_internalMutex); | 185 DeleteCriticalSection(&m_mutex.m_internalMutex); |
| 157 } | 186 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 } | 417 } |
| 389 | 418 |
| 390 void willCreateThread() { | 419 void willCreateThread() { |
| 391 s_threadCreated = true; | 420 s_threadCreated = true; |
| 392 } | 421 } |
| 393 #endif | 422 #endif |
| 394 | 423 |
| 395 } // namespace WTF | 424 } // namespace WTF |
| 396 | 425 |
| 397 #endif // OS(WIN) | 426 #endif // OS(WIN) |
| OLD | NEW |