Changeset 161818 in webkit
- Timestamp:
- Jan 12, 2014 11:45:00 AM (10 years ago)
- Location:
- trunk/Source
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WTF/ChangeLog
r161802 r161818 1 2014-01-12 Anders Carlsson <andersca@apple.com> 2 3 Replace more uses of AtomicallyInitializedStatic with std::call_once 4 https://bugs.webkit.org/show_bug.cgi?id=126847 5 6 Reviewed by Sam Weinig. 7 8 * wtf/Forward.h: 9 Forward declare NeverDestroyed. 10 1 11 2014-01-11 Zan Dobersek <zdobersek@igalia.com> 2 12 -
trunk/Source/WTF/wtf/Forward.h
r161518 r161818 27 27 28 28 template<typename T> class Function; 29 template<typename T> class NeverDestroyed; 29 30 template<typename T> class OwnPtr; 30 31 template<typename T> class PassOwnPtr; … … 60 61 using WTF::Function; 61 62 using WTF::FunctionDispatcher; 63 using WTF::NeverDestroyed; 62 64 using WTF::OwnPtr; 63 65 using WTF::PassOwnPtr; -
trunk/Source/WebCore/ChangeLog
r161817 r161818 1 2014-01-12 Anders Carlsson <andersca@apple.com> 2 3 Replace more uses of AtomicallyInitializedStatic with std::call_once 4 https://bugs.webkit.org/show_bug.cgi?id=126847 5 6 Reviewed by Sam Weinig. 7 8 * crypto/CryptoAlgorithmRegistry.cpp: 9 (WebCore::CryptoAlgorithmRegistry::shared): 10 (WebCore::registryMutex): 11 (WebCore::CryptoAlgorithmRegistry::getIdentifierForName): 12 (WebCore::CryptoAlgorithmRegistry::nameForIdentifier): 13 (WebCore::CryptoAlgorithmRegistry::create): 14 (WebCore::CryptoAlgorithmRegistry::registerAlgorithm): 15 * crypto/CryptoAlgorithmRegistry.h: 16 * inspector/WorkerDebuggerAgent.cpp: 17 (WebCore::WorkerDebuggerAgent::WorkerDebuggerAgent): 18 (WebCore::WorkerDebuggerAgent::~WorkerDebuggerAgent): 19 (WebCore::WorkerDebuggerAgent::interruptAndDispatchInspectorCommands): 20 * workers/WorkerThread.cpp: 21 (WebCore::threadSetMutex): 22 (WebCore::workerThreads): 23 (WebCore::WorkerThread::workerThreadCount): 24 (WebCore::WorkerThread::WorkerThread): 25 (WebCore::WorkerThread::~WorkerThread): 26 (WebCore::WorkerThread::releaseFastMallocFreeMemoryInAllThreads): 27 1 28 2014-01-11 Sam Weinig <sam@webkit.org> 2 29 -
trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.cpp
r160491 r161818 30 30 31 31 #include "CryptoAlgorithm.h" 32 #include <wtf/MainThread.h> 32 #include <mutex> 33 #include <wtf/NeverDestroyed.h> 33 34 34 35 namespace WebCore { … … 36 37 CryptoAlgorithmRegistry& CryptoAlgorithmRegistry::shared() 37 38 { 38 DEFINE_STATIC_LOCAL(CryptoAlgorithmRegistry, registry, ()); 39 static NeverDestroyed<CryptoAlgorithmRegistry> registry; 40 39 41 return registry; 40 42 } 41 43 42 static Mutex& registryMutex()44 static std::mutex& registryMutex() 43 45 { 44 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 45 return mutex; 46 static std::once_flag onceFlag; 47 static std::mutex* mutex; 48 49 std::call_once(onceFlag, []{ 50 mutex = std::make_unique<std::mutex>().release(); 51 }); 52 53 return *mutex; 46 54 } 47 55 … … 56 64 return false; 57 65 58 MutexLockerlock(registryMutex());66 std::lock_guard<std::mutex> lock(registryMutex()); 59 67 60 68 auto iter = m_nameToIdentifierMap.find(name.isolatedCopy()); … … 68 76 String CryptoAlgorithmRegistry::nameForIdentifier(CryptoAlgorithmIdentifier identifier) 69 77 { 70 MutexLockerlock(registryMutex());78 std::lock_guard<std::mutex> lock(registryMutex()); 71 79 72 80 return m_identifierToNameMap.get(static_cast<unsigned>(identifier)).isolatedCopy(); … … 75 83 std::unique_ptr<CryptoAlgorithm> CryptoAlgorithmRegistry::create(CryptoAlgorithmIdentifier identifier) 76 84 { 77 MutexLockerlock(registryMutex());85 std::lock_guard<std::mutex> lock(registryMutex()); 78 86 79 87 auto iter = m_identifierToConstructorMap.find(static_cast<unsigned>(identifier)); … … 86 94 void CryptoAlgorithmRegistry::registerAlgorithm(const String& name, CryptoAlgorithmIdentifier identifier, CryptoAlgorithmConstructor constructor) 87 95 { 88 MutexLockerlock(registryMutex());96 std::lock_guard<std::mutex> lock(registryMutex()); 89 97 90 98 bool added = m_nameToIdentifierMap.add(name, identifier).isNewEntry; -
trunk/Source/WebCore/crypto/CryptoAlgorithmRegistry.h
r160491 r161818 43 43 class CryptoAlgorithmRegistry { 44 44 WTF_MAKE_NONCOPYABLE(CryptoAlgorithmRegistry); 45 friend class NeverDestroyed<CryptoAlgorithmRegistry>; 45 46 46 47 public: … … 64 65 65 66 void registerAlgorithm(const String& name, CryptoAlgorithmIdentifier, CryptoAlgorithmConstructor); 67 66 68 HashMap<String, CryptoAlgorithmIdentifier, CaseFoldingHash> m_nameToIdentifierMap; 67 69 HashMap<unsigned, String> m_identifierToNameMap; -
trunk/Source/WebCore/inspector/WorkerDebuggerAgent.cpp
r161784 r161818 39 39 #include <inspector/InjectedScript.h> 40 40 #include <inspector/InjectedScriptManager.h> 41 #include <mutex> 41 42 #include <wtf/MessageQueue.h> 43 #include <wtf/NeverDestroyed.h> 42 44 43 45 using namespace Inspector; … … 47 49 namespace { 48 50 49 Mutex& workerDebuggerAgentsMutex()51 std::mutex& workerDebuggerAgentsMutex() 50 52 { 51 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 52 return mutex; 53 static std::once_flag onceFlag; 54 static std::mutex* mutex; 55 56 std::call_once(onceFlag, []{ 57 mutex = std::make_unique<std::mutex>().release(); 58 }); 59 60 return *mutex; 53 61 } 54 62 … … 57 65 WorkerDebuggerAgents& workerDebuggerAgents() 58 66 { 59 DEFINE_STATIC_LOCAL(WorkerDebuggerAgents, agents, ()); 67 static NeverDestroyed<WorkerDebuggerAgents> agents; 68 60 69 return agents; 61 70 } 62 63 71 64 72 class RunInspectorCommandsTask : public ScriptDebugServer::Task { … … 90 98 , m_inspectedWorkerGlobalScope(inspectedWorkerGlobalScope) 91 99 { 92 MutexLockerlock(workerDebuggerAgentsMutex());100 std::lock_guard<std::mutex> lock(workerDebuggerAgentsMutex()); 93 101 workerDebuggerAgents().set(inspectedWorkerGlobalScope->thread(), this); 94 102 } … … 96 104 WorkerDebuggerAgent::~WorkerDebuggerAgent() 97 105 { 98 MutexLocker lock(workerDebuggerAgentsMutex()); 106 std::lock_guard<std::mutex> lock(workerDebuggerAgentsMutex()); 107 99 108 ASSERT(workerDebuggerAgents().contains(m_inspectedWorkerGlobalScope->thread())); 100 109 workerDebuggerAgents().remove(m_inspectedWorkerGlobalScope->thread()); … … 103 112 void WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(WorkerThread* thread) 104 113 { 105 MutexLockerlock(workerDebuggerAgentsMutex());106 WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread); 107 if ( agent)114 std::lock_guard<std::mutex> lock(workerDebuggerAgentsMutex()); 115 116 if (WorkerDebuggerAgent* agent = workerDebuggerAgents().get(thread)) 108 117 agent->m_scriptDebugServer.interruptAndRunTask(adoptPtr(new RunInspectorCommandsTask(thread, agent->m_inspectedWorkerGlobalScope))); 109 118 } -
trunk/Source/WebCore/workers/WorkerThread.cpp
r161638 r161818 36 36 #include "URL.h" 37 37 #include <utility> 38 #include <wtf/NeverDestroyed.h> 38 39 #include <wtf/Noncopyable.h> 39 40 #include <wtf/text/WTFString.h> … … 50 51 namespace WebCore { 51 52 52 static Mutex& threadSetMutex() 53 { 54 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 55 return mutex; 53 static std::mutex& threadSetMutex() 54 { 55 static std::once_flag onceFlag; 56 static std::mutex* mutex; 57 58 std::call_once(onceFlag, []{ 59 mutex = std::make_unique<std::mutex>().release(); 60 }); 61 62 return *mutex; 56 63 } 57 64 58 65 static HashSet<WorkerThread*>& workerThreads() 59 66 { 60 DEFINE_STATIC_LOCAL(HashSet<WorkerThread*>, threads, ()); 61 return threads; 67 static NeverDestroyed<HashSet<WorkerThread*>> workerThreads; 68 69 return workerThreads; 62 70 } 63 71 64 72 unsigned WorkerThread::workerThreadCount() 65 73 { 66 MutexLocker lock(threadSetMutex()); 74 std::lock_guard<std::mutex> lock(threadSetMutex()); 75 67 76 return workerThreads().size(); 68 77 } … … 115 124 #endif 116 125 { 117 MutexLocker lock(threadSetMutex()); 126 std::lock_guard<std::mutex> lock(threadSetMutex()); 127 118 128 workerThreads().add(this); 119 129 } … … 121 131 WorkerThread::~WorkerThread() 122 132 { 123 MutexLocker lock(threadSetMutex()); 133 std::lock_guard<std::mutex> lock(threadSetMutex()); 134 124 135 ASSERT(workerThreads().contains(this)); 125 136 workerThreads().remove(this); … … 280 291 void WorkerThread::releaseFastMallocFreeMemoryInAllThreads() 281 292 { 282 MutexLocker lock(threadSetMutex()); 283 HashSet<WorkerThread*>& threads = workerThreads(); 284 HashSet<WorkerThread*>::iterator end = threads.end(); 285 for (HashSet<WorkerThread*>::iterator it = threads.begin(); it != end; ++it) 286 (*it)->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask)); 293 std::lock_guard<std::mutex> lock(threadSetMutex()); 294 295 for (auto* workerThread : workerThreads()) 296 workerThread->runLoop().postTask(adoptPtr(new ReleaseFastMallocFreeMemoryTask)); 287 297 } 288 298
Note: See TracChangeset
for help on using the changeset viewer.