| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 #endif | 73 #endif |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace internal | 76 } // namespace internal |
| 77 | 77 |
| 78 static Mutex* atomicallyInitializedStaticMutex; | 78 static Mutex* atomicallyInitializedStaticMutex; |
| 79 | 79 |
| 80 void initializeThreading() { | 80 void initializeThreading() { |
| 81 // This should only be called once. | 81 // This should only be called once. |
| 82 DCHECK(!atomicallyInitializedStaticMutex); | 82 DCHECK(!atomicallyInitializedStaticMutex); |
| 83 WTFThreadData::initialize(); |
| 83 | 84 |
| 84 // StringImpl::empty() does not construct its static string in a threadsafe | 85 // StringImpl::empty() does not construct its static string in a threadsafe |
| 85 // fashion, so ensure it has been initialized from here. | 86 // fashion, so ensure it has been initialized from here. |
| 86 StringImpl::empty(); | 87 StringImpl::empty(); |
| 87 StringImpl::empty16Bit(); | 88 StringImpl::empty16Bit(); |
| 88 atomicallyInitializedStaticMutex = new Mutex; | 89 atomicallyInitializedStaticMutex = new Mutex; |
| 89 wtfThreadData(); | |
| 90 initializeDates(); | 90 initializeDates(); |
| 91 // Force initialization of static DoubleToStringConverter converter variable | 91 // Force initialization of static DoubleToStringConverter converter variable |
| 92 // inside EcmaScriptConverter function while we are in single thread mode. | 92 // inside EcmaScriptConverter function while we are in single thread mode. |
| 93 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 93 double_conversion::DoubleToStringConverter::EcmaScriptConverter(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void lockAtomicallyInitializedStaticMutex() { | 96 void lockAtomicallyInitializedStaticMutex() { |
| 97 DCHECK(atomicallyInitializedStaticMutex); | 97 DCHECK(atomicallyInitializedStaticMutex); |
| 98 atomicallyInitializedStaticMutex->lock(); | 98 atomicallyInitializedStaticMutex->lock(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void unlockAtomicallyInitializedStaticMutex() { | 101 void unlockAtomicallyInitializedStaticMutex() { |
| 102 atomicallyInitializedStaticMutex->unlock(); | 102 atomicallyInitializedStaticMutex->unlock(); |
| 103 } | 103 } |
| 104 | 104 |
| 105 ThreadIdentifier currentThread() { | 105 ThreadIdentifier currentThread() { |
| 106 // TLS lookup is fast on these platforms. | 106 return WTFThreadData::current().threadId(); |
| 107 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) | |
| 108 return wtfThreadData().threadId(); | |
| 109 #else | |
| 110 // TODO(csharrison): For platforms where TLS lookup is slow, use the hack that | |
| 111 // oilpan uses in ThreadState::current() to check if this is the main thread | |
| 112 // via stack address. | |
| 113 return internal::currentThreadSyscall(); | |
| 114 #endif | |
| 115 } | 107 } |
| 116 | 108 |
| 117 MutexBase::MutexBase(bool recursive) { | 109 MutexBase::MutexBase(bool recursive) { |
| 118 pthread_mutexattr_t attr; | 110 pthread_mutexattr_t attr; |
| 119 pthread_mutexattr_init(&attr); | 111 pthread_mutexattr_init(&attr); |
| 120 pthread_mutexattr_settype( | 112 pthread_mutexattr_settype( |
| 121 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); | 113 &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); |
| 122 | 114 |
| 123 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); | 115 int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); |
| 124 DCHECK_EQ(result, 0); | 116 DCHECK_EQ(result, 0); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } | 246 } |
| 255 | 247 |
| 256 void willCreateThread() { | 248 void willCreateThread() { |
| 257 s_threadCreated = true; | 249 s_threadCreated = true; |
| 258 } | 250 } |
| 259 #endif | 251 #endif |
| 260 | 252 |
| 261 } // namespace WTF | 253 } // namespace WTF |
| 262 | 254 |
| 263 #endif // OS(POSIX) | 255 #endif // OS(POSIX) |
| OLD | NEW |