| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DWORD dwType; // must be 0x1000 | 121 DWORD dwType; // must be 0x1000 |
| 122 LPCSTR szName; // pointer to name (in user addr space) | 122 LPCSTR szName; // pointer to name (in user addr space) |
| 123 DWORD dwThreadID; // thread ID (-1=caller thread) | 123 DWORD dwThreadID; // thread ID (-1=caller thread) |
| 124 DWORD dwFlags; // reserved for future use, must be zero | 124 DWORD dwFlags; // reserved for future use, must be zero |
| 125 } THREADNAME_INFO; | 125 } THREADNAME_INFO; |
| 126 #pragma pack(pop) | 126 #pragma pack(pop) |
| 127 | 127 |
| 128 static Mutex* atomicallyInitializedStaticMutex; | 128 static Mutex* atomicallyInitializedStaticMutex; |
| 129 | 129 |
| 130 void lockAtomicallyInitializedStaticMutex() { | 130 void lockAtomicallyInitializedStaticMutex() { |
| 131 ASSERT(atomicallyInitializedStaticMutex); | 131 DCHECK(atomicallyInitializedStaticMutex); |
| 132 atomicallyInitializedStaticMutex->lock(); | 132 atomicallyInitializedStaticMutex->lock(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void unlockAtomicallyInitializedStaticMutex() { | 135 void unlockAtomicallyInitializedStaticMutex() { |
| 136 atomicallyInitializedStaticMutex->unlock(); | 136 atomicallyInitializedStaticMutex->unlock(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void initializeThreading() { | 139 void initializeThreading() { |
| 140 // This should only be called once. | 140 // This should only be called once. |
| 141 ASSERT(!atomicallyInitializedStaticMutex); | 141 DCHECK(!atomicallyInitializedStaticMutex); |
| 142 | 142 |
| 143 // StringImpl::empty() does not construct its static string in a threadsafe | 143 // StringImpl::empty() does not construct its static string in a threadsafe |
| 144 // fashion, so ensure it has been initialized from here. | 144 // fashion, so ensure it has been initialized from here. |
| 145 StringImpl::empty(); | 145 StringImpl::empty(); |
| 146 StringImpl::empty16Bit(); | 146 StringImpl::empty16Bit(); |
| 147 atomicallyInitializedStaticMutex = new Mutex; | 147 atomicallyInitializedStaticMutex = new Mutex; |
| 148 wtfThreadData(); | 148 wtfThreadData(); |
| 149 initializeDates(); | 149 initializeDates(); |
| 150 // Force initialization of static DoubleToStringConverter converter variable | 150 // Force initialization of static DoubleToStringConverter converter variable |
| 151 // inside EcmaScriptConverter function while we are in single thread mode. | 151 // inside EcmaScriptConverter function while we are in single thread mode. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 164 MutexBase::~MutexBase() { | 164 MutexBase::~MutexBase() { |
| 165 DeleteCriticalSection(&m_mutex.m_internalMutex); | 165 DeleteCriticalSection(&m_mutex.m_internalMutex); |
| 166 } | 166 } |
| 167 | 167 |
| 168 void MutexBase::lock() { | 168 void MutexBase::lock() { |
| 169 EnterCriticalSection(&m_mutex.m_internalMutex); | 169 EnterCriticalSection(&m_mutex.m_internalMutex); |
| 170 ++m_mutex.m_recursionCount; | 170 ++m_mutex.m_recursionCount; |
| 171 } | 171 } |
| 172 | 172 |
| 173 void MutexBase::unlock() { | 173 void MutexBase::unlock() { |
| 174 ASSERT(m_mutex.m_recursionCount); | 174 DCHECK(m_mutex.m_recursionCount); |
| 175 --m_mutex.m_recursionCount; | 175 --m_mutex.m_recursionCount; |
| 176 LeaveCriticalSection(&m_mutex.m_internalMutex); | 176 LeaveCriticalSection(&m_mutex.m_internalMutex); |
| 177 } | 177 } |
| 178 | 178 |
| 179 bool Mutex::tryLock() { | 179 bool Mutex::tryLock() { |
| 180 // This method is modeled after the behavior of pthread_mutex_trylock, | 180 // This method is modeled after the behavior of pthread_mutex_trylock, |
| 181 // which will return an error if the lock is already owned by the | 181 // which will return an error if the lock is already owned by the |
| 182 // current thread. Since the primitive Win32 'TryEnterCriticalSection' | 182 // current thread. Since the primitive Win32 'TryEnterCriticalSection' |
| 183 // treats this as a successful case, it changes the behavior of several | 183 // treats this as a successful case, it changes the behavior of several |
| 184 // tests in WebKit that check to see if the current thread already | 184 // tests in WebKit that check to see if the current thread already |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 return 0; | 382 return 0; |
| 383 | 383 |
| 384 // Time is too far in the future (and would overflow unsigned long) - wait | 384 // Time is too far in the future (and would overflow unsigned long) - wait |
| 385 // forever. | 385 // forever. |
| 386 if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) | 386 if (absoluteTime - currentTime > static_cast<double>(INT_MAX) / 1000.0) |
| 387 return INFINITE; | 387 return INFINITE; |
| 388 | 388 |
| 389 return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0); | 389 return static_cast<DWORD>((absoluteTime - currentTime) * 1000.0); |
| 390 } | 390 } |
| 391 | 391 |
| 392 #if ENABLE(ASSERT) | 392 #if DCHECK_IS_ON() |
| 393 static bool s_threadCreated = false; | 393 static bool s_threadCreated = false; |
| 394 | 394 |
| 395 bool isAtomicallyInitializedStaticMutexLockHeld() { | 395 bool isAtomicallyInitializedStaticMutexLockHeld() { |
| 396 return atomicallyInitializedStaticMutex && | 396 return atomicallyInitializedStaticMutex && |
| 397 atomicallyInitializedStaticMutex->locked(); | 397 atomicallyInitializedStaticMutex->locked(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 bool isBeforeThreadCreated() { | 400 bool isBeforeThreadCreated() { |
| 401 return !s_threadCreated; | 401 return !s_threadCreated; |
| 402 } | 402 } |
| 403 | 403 |
| 404 void willCreateThread() { | 404 void willCreateThread() { |
| 405 s_threadCreated = true; | 405 s_threadCreated = true; |
| 406 } | 406 } |
| 407 #endif | 407 #endif |
| 408 | 408 |
| 409 } // namespace WTF | 409 } // namespace WTF |
| 410 | 410 |
| 411 #endif // OS(WIN) | 411 #endif // OS(WIN) |
| OLD | NEW |