Use std::mutex instead of WTF::Mutex in WTF
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jan 2014 17:13:41 +0000 (17:13 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Jan 2014 17:13:41 +0000 (17:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=127783

Reviewed by Antti Koivisto.

* wtf/CryptographicallyRandomNumber.cpp:
* wtf/MainThread.cpp:
(WTF::mainThreadFunctionQueueMutex):
(WTF::functionQueue):
(WTF::dispatchFunctionsFromMainThread):
(WTF::callOnMainThread):
(WTF::cancelCallOnMainThread):
* wtf/StackStats.cpp:
(WTF::StackStats::initialize):
(WTF::StackStats::CheckPoint::CheckPoint):
(WTF::StackStats::CheckPoint::~CheckPoint):
(WTF::StackStats::probe):
(WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
(WTF::StackStats::LayoutCheckPoint::~LayoutCheckPoint):
* wtf/StackStats.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@162935 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/CryptographicallyRandomNumber.cpp
Source/WTF/wtf/MainThread.cpp
Source/WTF/wtf/StackStats.cpp
Source/WTF/wtf/StackStats.h

index ed864b7..4e95351 100644 (file)
@@ -1,3 +1,26 @@
+2014-01-28  Anders Carlsson  <andersca@apple.com>
+
+        Use std::mutex instead of WTF::Mutex in WTF
+        https://bugs.webkit.org/show_bug.cgi?id=127783
+
+        Reviewed by Antti Koivisto.
+
+        * wtf/CryptographicallyRandomNumber.cpp:
+        * wtf/MainThread.cpp:
+        (WTF::mainThreadFunctionQueueMutex):
+        (WTF::functionQueue):
+        (WTF::dispatchFunctionsFromMainThread):
+        (WTF::callOnMainThread):
+        (WTF::cancelCallOnMainThread):
+        * wtf/StackStats.cpp:
+        (WTF::StackStats::initialize):
+        (WTF::StackStats::CheckPoint::CheckPoint):
+        (WTF::StackStats::CheckPoint::~CheckPoint):
+        (WTF::StackStats::probe):
+        (WTF::StackStats::LayoutCheckPoint::LayoutCheckPoint):
+        (WTF::StackStats::LayoutCheckPoint::~LayoutCheckPoint):
+        * wtf/StackStats.h:
+
 2014-01-27  Joseph Pecoraro  <pecoraro@apple.com>
 
         WebCore: Enable -Wimplicit-fallthrough and add FALLTHROUGH annotation where needed
index a0aecfe..1236086 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "NeverDestroyed.h"
 #include "OSRandomSource.h"
-#include "ThreadingPrimitives.h"
+#include <mutex>
 
 namespace WTF {
 
@@ -64,7 +64,7 @@ private:
 
     ARC4Stream m_stream;
     int m_count;
-    Mutex m_mutex;
+    std::mutex m_mutex;
 };
 
 ARC4Stream::ARC4Stream()
@@ -136,7 +136,7 @@ uint32_t ARC4RandomNumberGenerator::getWord()
 
 uint32_t ARC4RandomNumberGenerator::randomNumber()
 {
-    MutexLocker locker(m_mutex);
+    std::lock_guard<std::mutex> lock(m_mutex);
 
     m_count -= 4;
     stirIfNeeded();
@@ -145,7 +145,7 @@ uint32_t ARC4RandomNumberGenerator::randomNumber()
 
 void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length)
 {
-    MutexLocker locker(m_mutex);
+    std::lock_guard<std::mutex> lock(m_mutex);
 
     unsigned char* result = reinterpret_cast<unsigned char*>(buffer);
     stirIfNeeded();
index 8790cca..b3d63d4 100644 (file)
@@ -33,7 +33,8 @@
 #include "Deque.h"
 #include "Functional.h"
 #include "StdLibExtras.h"
-#include "Threading.h"
+#include <mutex>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/ThreadSpecific.h>
 
 namespace WTF {
@@ -68,16 +69,17 @@ static bool callbacksPaused; // This global variable is only accessed from main
 static ThreadIdentifier mainThreadIdentifier;
 #endif
 
-static Mutex& mainThreadFunctionQueueMutex()
+static std::mutex& mainThreadFunctionQueueMutex()
 {
-    DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
-    return staticMutex;
+    static NeverDestroyed<std::mutex> mutex;
+    
+    return mutex;
 }
 
 static FunctionQueue& functionQueue()
 {
-    DEFINE_STATIC_LOCAL(FunctionQueue, staticFunctionQueue, ());
-    return staticFunctionQueue;
+    static NeverDestroyed<FunctionQueue> functionQueue;
+    return functionQueue;
 }
 
 
@@ -154,7 +156,7 @@ void dispatchFunctionsFromMainThread()
     FunctionWithContext invocation;
     while (true) {
         {
-            MutexLocker locker(mainThreadFunctionQueueMutex());
+            std::lock_guard<std::mutex> lock(mainThreadFunctionQueueMutex());
             if (!functionQueue().size())
                 break;
             invocation = functionQueue().takeFirst();
@@ -178,7 +180,7 @@ void callOnMainThread(MainThreadFunction* function, void* context)
     ASSERT(function);
     bool needToSchedule = false;
     {
-        MutexLocker locker(mainThreadFunctionQueueMutex());
+        std::lock_guard<std::mutex> lock(mainThreadFunctionQueueMutex());
         needToSchedule = functionQueue().size() == 0;
         functionQueue().append(FunctionWithContext(function, context));
     }
@@ -190,7 +192,7 @@ void cancelCallOnMainThread(MainThreadFunction* function, void* context)
 {
     ASSERT(function);
 
-    MutexLocker locker(mainThreadFunctionQueueMutex());
+    std::lock_guard<std::mutex> lock(mainThreadFunctionQueueMutex());
 
     FunctionWithContextFinder pred(FunctionWithContext(function, context));
 
index 824bf46..5c353bc 100644 (file)
 // checkpoint. By default, we only log checkpoints that establish new
 // max values.
 
-// #define ENABLE_VERBOSE_STACK_STATS 1
+#define ENABLE_VERBOSE_STACK_STATS 1
 
 
 namespace WTF {
 
 // CheckPoint management:
-Mutex* StackStats::s_sharedLock = 0;
+std::mutex* StackStats::s_sharedMutex = 0;
 StackStats::CheckPoint* StackStats::s_topCheckPoint = 0;
 StackStats::LayoutCheckPoint* StackStats::s_firstLayoutCheckPoint = 0;
 StackStats::LayoutCheckPoint* StackStats::s_topLayoutCheckPoint = 0;
@@ -60,7 +60,7 @@ int StackStats::s_maxLayoutReentryDepth = 0;
 // Initializes locks and the log. Should only be called once.
 void StackStats::initialize()
 {
-    s_sharedLock = new Mutex();
+    s_sharedMutex = std::make_unique<std::mutex>().release();
     dataLogF(" === LOG new stack stats ========\n");
 }
 
@@ -76,7 +76,7 @@ StackStats::PerThreadStats::PerThreadStats()
 
 StackStats::CheckPoint::CheckPoint()
 {
-    MutexLocker locker(*StackStats::s_sharedLock);
+    std::lock_guard<std::mutex> lock(*StackStats::s_sharedMutex);
     WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
     StackStats::PerThreadStats& t = threadData->stackStats();
     const StackBounds& stack = threadData->stack();
@@ -134,7 +134,7 @@ StackStats::CheckPoint::CheckPoint()
 
 StackStats::CheckPoint::~CheckPoint()
 {
-    MutexLocker locker(*StackStats::s_sharedLock);
+    std::lock_guard<std::mutex> lock(*StackStats::s_sharedMutex);
     WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
     StackStats::PerThreadStats& t = threadData->stackStats();
 
@@ -165,7 +165,7 @@ StackStats::CheckPoint::~CheckPoint()
 
 void StackStats::probe()
 {
-    MutexLocker locker(*StackStats::s_sharedLock);
+    std::lock_guard<std::mutex> lock(*StackStats::s_sharedMutex);
     WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
     StackStats::PerThreadStats& t = threadData->stackStats();
     const StackBounds& stack = threadData->stack();
@@ -226,7 +226,7 @@ StackStats::LayoutCheckPoint::LayoutCheckPoint()
     // probe first, we can avoid re-entering the lock.
     StackStats::probe();
 
-    MutexLocker locker(*StackStats::s_sharedLock);
+    std::lock_guard<std::mutex> lock(*StackStats::s_sharedMutex);
     WTFThreadData* threadData = const_cast<WTFThreadData*>(&wtfThreadData());
     StackStats::PerThreadStats& t = threadData->stackStats();
     const StackBounds& stack = threadData->stack();
@@ -295,7 +295,7 @@ StackStats::LayoutCheckPoint::LayoutCheckPoint()
 
 StackStats::LayoutCheckPoint::~LayoutCheckPoint()
 {
-    MutexLocker locker(*StackStats::s_sharedLock);
+    std::lock_guard<std::mutex> lock(*StackStats::s_sharedMutex);
 
     // Pop to the previous layout checkpoint:
     StackStats::s_topLayoutCheckPoint = m_prev;
index 2635679..fe43141 100644 (file)
@@ -27,7 +27,7 @@
 #define StackStats_h
 
 #include "ExportMacros.h"
-#include "ThreadingPrimitives.h"
+#include <mutex>
 
 
 // Define this flag to enable Stack stats collection. This feature is useful
@@ -40,7 +40,7 @@
 // convenience for collecting that data. It is not meant to be enabled by
 // default on release or debug builds.
 
-// #define ENABLE_STACK_STATS 1
+#define ENABLE_STACK_STATS 1
 
 
 namespace WTF {
@@ -124,7 +124,7 @@ public:
 
 private:
     // CheckPoint management:
-    static Mutex* s_sharedLock;
+    static std::mutex* s_sharedMutex;
     static CheckPoint* s_topCheckPoint;
     static LayoutCheckPoint* s_firstLayoutCheckPoint;
     static LayoutCheckPoint* s_topLayoutCheckPoint;