Title: [173240] trunk/Source/WebCore
Revision
173240
Author
ander...@apple.com
Date
2014-09-03 15:56:48 -0700 (Wed, 03 Sep 2014)

Log Message

Don't use DEPRECATED_DEFINE_STATIC_LOCAL for mutexes
https://bugs.webkit.org/show_bug.cgi?id=136510

Reviewed by Andreas Kling.

Mutexes are intended to be used from multiple threads, and DEPRECATED_DEFINE_STATIC_LOCAL is not thread safe.

* bindings/objc/DOMInternal.mm:
(wrapperCacheLock):
(getDOMWrapper):
(addDOMWrapper):
(removeDOMWrapper):
Use LazyNeverDestroyed + std::call_once, and switch the mutex over to an std::mutex.

* dom/EventListenerMap.cpp:
(WebCore::EventListenerMap::assertNoActiveIterators):
(WebCore::EventListenerIterator::EventListenerIterator):
(WebCore::EventListenerIterator::~EventListenerIterator):
(WebCore::activeIteratorCountMutex):
(WebCore::EventListenerMap::EventListenerMap): Deleted.
* dom/EventListenerMap.h:
Use an std::atomic<int> instead of a mutex here.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (173239 => 173240)


--- trunk/Source/WebCore/ChangeLog	2014-09-03 22:55:02 UTC (rev 173239)
+++ trunk/Source/WebCore/ChangeLog	2014-09-03 22:56:48 UTC (rev 173240)
@@ -1,3 +1,28 @@
+2014-09-03  Anders Carlsson  <ander...@apple.com>
+
+        Don't use DEPRECATED_DEFINE_STATIC_LOCAL for mutexes
+        https://bugs.webkit.org/show_bug.cgi?id=136510
+
+        Reviewed by Andreas Kling.
+
+        Mutexes are intended to be used from multiple threads, and DEPRECATED_DEFINE_STATIC_LOCAL is not thread safe.
+
+        * bindings/objc/DOMInternal.mm:
+        (wrapperCacheLock):
+        (getDOMWrapper):
+        (addDOMWrapper):
+        (removeDOMWrapper):
+        Use LazyNeverDestroyed + std::call_once, and switch the mutex over to an std::mutex.
+
+        * dom/EventListenerMap.cpp:
+        (WebCore::EventListenerMap::assertNoActiveIterators):
+        (WebCore::EventListenerIterator::EventListenerIterator):
+        (WebCore::EventListenerIterator::~EventListenerIterator):
+        (WebCore::activeIteratorCountMutex):
+        (WebCore::EventListenerMap::EventListenerMap): Deleted.
+        * dom/EventListenerMap.h:
+        Use an std::atomic<int> instead of a mutex here.
+
 2014-09-03  Enrica Casucci  <enr...@apple.com>
 
         Remove PLATFORM(IOS) from WebCore/editing (Part 1).

Modified: trunk/Source/WebCore/bindings/objc/DOMInternal.mm (173239 => 173240)


--- trunk/Source/WebCore/bindings/objc/DOMInternal.mm	2014-09-03 22:55:02 UTC (rev 173239)
+++ trunk/Source/WebCore/bindings/objc/DOMInternal.mm	2014-09-03 22:56:48 UTC (rev 173240)
@@ -32,6 +32,7 @@
 #import "ScriptController.h"
 #import "WebScriptObjectPrivate.h"
 #import "runtime_root.h"
+#import <wtf/NeverDestroyed.h>
 
 #if PLATFORM(IOS)
 #define NEEDS_WRAPPER_CACHE_LOCK 1
@@ -43,10 +44,15 @@
 static NSMapTable* DOMWrapperCache;
     
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-static Mutex& wrapperCacheLock()
+static std::mutex& wrapperCacheLock()
 {
-    DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, wrapperCacheMutex, ());
-    return wrapperCacheMutex;
+    static std::once_flag onceFlag;
+    static LazyNeverDestroyed<std::mutex> mutex;
+
+    std::call_once(onceFlag, [] {
+        mutex.construct();
+    });
+    return mutex;
 }
 #endif
 
@@ -70,7 +76,7 @@
 NSObject* getDOMWrapper(DOMObjectInternal* impl)
 {
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-    MutexLocker locker(wrapperCacheLock());
+    std::lock_guard<std::mutex> lock(wrapperCacheLock());
 #endif
     if (!DOMWrapperCache)
         return nil;
@@ -80,7 +86,7 @@
 void addDOMWrapper(NSObject* wrapper, DOMObjectInternal* impl)
 {
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-    MutexLocker locker(wrapperCacheLock());
+    std::lock_guard<std::mutex> lock(wrapperCacheLock());
 #endif
     if (!DOMWrapperCache)
         DOMWrapperCache = createWrapperCache();
@@ -90,7 +96,7 @@
 void removeDOMWrapper(DOMObjectInternal* impl)
 {
 #ifdef NEEDS_WRAPPER_CACHE_LOCK
-    MutexLocker locker(wrapperCacheLock());
+    std::lock_guard<std::mutex> lock(wrapperCacheLock());
 #endif
     if (!DOMWrapperCache)
         return;

Modified: trunk/Source/WebCore/dom/EventListenerMap.cpp (173239 => 173240)


--- trunk/Source/WebCore/dom/EventListenerMap.cpp	2014-09-03 22:55:02 UTC (rev 173239)
+++ trunk/Source/WebCore/dom/EventListenerMap.cpp	2014-09-03 22:56:48 UTC (rev 173240)
@@ -37,35 +37,22 @@
 #include "EventException.h"
 #include "EventTarget.h"
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 #include <wtf/StdLibExtras.h>
 #include <wtf/Vector.h>
 
-#ifndef NDEBUG
-#include <wtf/Threading.h>
-#endif
-
 using namespace WTF;
 
 namespace WebCore {
 
 #ifndef NDEBUG
-static Mutex& activeIteratorCountMutex()
-{
-    DEPRECATED_DEFINE_STATIC_LOCAL(Mutex, mutex, ());
-    return mutex;
-}
-
 void EventListenerMap::assertNoActiveIterators()
 {
-    MutexLocker locker(activeIteratorCountMutex());
     ASSERT(!m_activeIteratorCount);
 }
 #endif
 
 EventListenerMap::EventListenerMap()
-#ifndef NDEBUG
-    : m_activeIteratorCount(0)
-#endif
 {
 }
 
@@ -240,20 +227,15 @@
     m_map = &data->eventListenerMap;
 
 #ifndef NDEBUG
-    {
-        MutexLocker locker(activeIteratorCountMutex());
-        m_map->m_activeIteratorCount++;
-    }
+    m_map->m_activeIteratorCount++;
 #endif
 }
 
 #ifndef NDEBUG
 EventListenerIterator::~EventListenerIterator()
 {
-    if (m_map) {
-        MutexLocker locker(activeIteratorCountMutex());
+    if (m_map)
         m_map->m_activeIteratorCount--;
-    }
 }
 #endif
 

Modified: trunk/Source/WebCore/dom/EventListenerMap.h (173239 => 173240)


--- trunk/Source/WebCore/dom/EventListenerMap.h	2014-09-03 22:55:02 UTC (rev 173239)
+++ trunk/Source/WebCore/dom/EventListenerMap.h	2014-09-03 22:56:48 UTC (rev 173240)
@@ -69,7 +69,7 @@
     Vector<std::pair<AtomicString, std::unique_ptr<EventListenerVector>>, 2> m_entries;
 
 #ifndef NDEBUG
-    int m_activeIteratorCount;
+    std::atomic<int> m_activeIteratorCount { 0 };
 #endif
 };
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to