Title: [162935] trunk/Source/WTF
Revision
162935
Author
ander...@apple.com
Date
2014-01-28 09:13:41 -0800 (Tue, 28 Jan 2014)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (162934 => 162935)


--- trunk/Source/WTF/ChangeLog	2014-01-28 17:07:38 UTC (rev 162934)
+++ trunk/Source/WTF/ChangeLog	2014-01-28 17:13:41 UTC (rev 162935)
@@ -1,3 +1,26 @@
+2014-01-28  Anders Carlsson  <ander...@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  <pecor...@apple.com>
 
         WebCore: Enable -Wimplicit-fallthrough and add FALLTHROUGH annotation where needed

Modified: trunk/Source/WTF/wtf/CryptographicallyRandomNumber.cpp (162934 => 162935)


--- trunk/Source/WTF/wtf/CryptographicallyRandomNumber.cpp	2014-01-28 17:07:38 UTC (rev 162934)
+++ trunk/Source/WTF/wtf/CryptographicallyRandomNumber.cpp	2014-01-28 17:13:41 UTC (rev 162935)
@@ -32,7 +32,7 @@
 
 #include "NeverDestroyed.h"
 #include "OSRandomSource.h"
-#include "ThreadingPrimitives.h"
+#include <mutex>
 
 namespace WTF {
 
@@ -64,7 +64,7 @@
 
     ARC4Stream m_stream;
     int m_count;
-    Mutex m_mutex;
+    std::mutex m_mutex;
 };
 
 ARC4Stream::ARC4Stream()
@@ -136,7 +136,7 @@
 
 uint32_t ARC4RandomNumberGenerator::randomNumber()
 {
-    MutexLocker locker(m_mutex);
+    std::lock_guard<std::mutex> lock(m_mutex);
 
     m_count -= 4;
     stirIfNeeded();
@@ -145,7 +145,7 @@
 
 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();

Modified: trunk/Source/WTF/wtf/MainThread.cpp (162934 => 162935)


--- trunk/Source/WTF/wtf/MainThread.cpp	2014-01-28 17:07:38 UTC (rev 162934)
+++ trunk/Source/WTF/wtf/MainThread.cpp	2014-01-28 17:13:41 UTC (rev 162935)
@@ -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 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 @@
     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 @@
     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 @@
 {
     ASSERT(function);
 
-    MutexLocker locker(mainThreadFunctionQueueMutex());
+    std::lock_guard<std::mutex> lock(mainThreadFunctionQueueMutex());
 
     FunctionWithContextFinder pred(FunctionWithContext(function, context));
 

Modified: trunk/Source/WTF/wtf/StackStats.cpp (162934 => 162935)


--- trunk/Source/WTF/wtf/StackStats.cpp	2014-01-28 17:07:38 UTC (rev 162934)
+++ trunk/Source/WTF/wtf/StackStats.cpp	2014-01-28 17:13:41 UTC (rev 162935)
@@ -36,13 +36,13 @@
 // 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 @@
 // 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::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()
 {
-    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 @@
 
 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 @@
     // 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()
 {
-    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;

Modified: trunk/Source/WTF/wtf/StackStats.h (162934 => 162935)


--- trunk/Source/WTF/wtf/StackStats.h	2014-01-28 17:07:38 UTC (rev 162934)
+++ trunk/Source/WTF/wtf/StackStats.h	2014-01-28 17:13:41 UTC (rev 162935)
@@ -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 @@
 
 private:
     // CheckPoint management:
-    static Mutex* s_sharedLock;
+    static std::mutex* s_sharedMutex;
     static CheckPoint* s_topCheckPoint;
     static LayoutCheckPoint* s_firstLayoutCheckPoint;
     static LayoutCheckPoint* s_topLayoutCheckPoint;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to