Title: [277847] trunk/Source/WTF
Revision
277847
Author
[email protected]
Date
2021-05-20 19:43:18 -0700 (Thu, 20 May 2021)

Log Message

Use CheckedLock more in WTF
https://bugs.webkit.org/show_bug.cgi?id=226045

Reviewed by Darin Adler.

Use CheckedLock more in WTF to benefit from Clang Thread Safety Analysis.

* wtf/CrossThreadQueue.h:
(WTF::CrossThreadQueue<DataType>::append):
(WTF::CrossThreadQueue<DataType>::waitForMessage):
(WTF::CrossThreadQueue<DataType>::tryGetMessage):
(WTF::CrossThreadQueue<DataType>::kill):
(WTF::CrossThreadQueue<DataType>::isKilled const):
(WTF::CrossThreadQueue<DataType>::isEmpty const):
* wtf/CrossThreadTaskHandler.cpp:
(WTF::CrossThreadTaskHandler::postTaskReply):
(WTF::CrossThreadTaskHandler::handleTaskRepliesOnMainThread):
* wtf/CrossThreadTaskHandler.h:
(WTF::CrossThreadTaskHandler::WTF_GUARDED_BY_LOCK):
* wtf/CryptographicallyRandomNumber.cpp:
* wtf/FastMalloc.cpp:
(WTF::MallocCallTracker::recordMalloc):
(WTF::MallocCallTracker::recordRealloc):
(WTF::MallocCallTracker::recordFree):
(WTF::MallocCallTracker::dumpStats):
* wtf/MessageQueue.h:
(WTF::MessageQueue<DataType>::append):
(WTF::MessageQueue<DataType>::appendAndKill):
(WTF::MessageQueue<DataType>::appendAndCheckEmpty):
(WTF::MessageQueue<DataType>::prepend):
(WTF::MessageQueue<DataType>::waitForMessageFilteredWithTimeout):
(WTF::MessageQueue<DataType>::tryGetMessage):
(WTF::MessageQueue<DataType>::takeAllMessages):
(WTF::MessageQueue<DataType>::tryGetMessageIgnoringKilled):
(WTF::MessageQueue<DataType>::removeIf):
(WTF::MessageQueue<DataType>::isEmpty):
(WTF::MessageQueue<DataType>::kill):
(WTF::MessageQueue<DataType>::killed const):
* wtf/OSLogPrintStream.cpp:
(WTF::OSLogPrintStream::vprintf):
* wtf/OSLogPrintStream.h:
* wtf/ParallelJobsGeneric.h:
(WTF::ParallelEnvironment::ThreadPrivate::WTF_GUARDED_BY_LOCK):
* wtf/ParallelVectorIterator.h:
(WTF::ParallelVectorIterator::iterate):
(WTF::ParallelVectorIterator::WTF_GUARDED_BY_LOCK):
* wtf/ReadWriteLock.cpp:
(WTF::ReadWriteLock::readLock):
(WTF::ReadWriteLock::readUnlock):
(WTF::ReadWriteLock::writeLock):
(WTF::ReadWriteLock::writeUnlock):
* wtf/ReadWriteLock.h:
(WTF::ReadWriteLock::WTF_GUARDED_BY_LOCK):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (277846 => 277847)


--- trunk/Source/WTF/ChangeLog	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/ChangeLog	2021-05-21 02:43:18 UTC (rev 277847)
@@ -1,5 +1,61 @@
 2021-05-20  Chris Dumez  <[email protected]>
 
+        Use CheckedLock more in WTF
+        https://bugs.webkit.org/show_bug.cgi?id=226045
+
+        Reviewed by Darin Adler.
+
+        Use CheckedLock more in WTF to benefit from Clang Thread Safety Analysis.
+
+        * wtf/CrossThreadQueue.h:
+        (WTF::CrossThreadQueue<DataType>::append):
+        (WTF::CrossThreadQueue<DataType>::waitForMessage):
+        (WTF::CrossThreadQueue<DataType>::tryGetMessage):
+        (WTF::CrossThreadQueue<DataType>::kill):
+        (WTF::CrossThreadQueue<DataType>::isKilled const):
+        (WTF::CrossThreadQueue<DataType>::isEmpty const):
+        * wtf/CrossThreadTaskHandler.cpp:
+        (WTF::CrossThreadTaskHandler::postTaskReply):
+        (WTF::CrossThreadTaskHandler::handleTaskRepliesOnMainThread):
+        * wtf/CrossThreadTaskHandler.h:
+        (WTF::CrossThreadTaskHandler::WTF_GUARDED_BY_LOCK):
+        * wtf/CryptographicallyRandomNumber.cpp:
+        * wtf/FastMalloc.cpp:
+        (WTF::MallocCallTracker::recordMalloc):
+        (WTF::MallocCallTracker::recordRealloc):
+        (WTF::MallocCallTracker::recordFree):
+        (WTF::MallocCallTracker::dumpStats):
+        * wtf/MessageQueue.h:
+        (WTF::MessageQueue<DataType>::append):
+        (WTF::MessageQueue<DataType>::appendAndKill):
+        (WTF::MessageQueue<DataType>::appendAndCheckEmpty):
+        (WTF::MessageQueue<DataType>::prepend):
+        (WTF::MessageQueue<DataType>::waitForMessageFilteredWithTimeout):
+        (WTF::MessageQueue<DataType>::tryGetMessage):
+        (WTF::MessageQueue<DataType>::takeAllMessages):
+        (WTF::MessageQueue<DataType>::tryGetMessageIgnoringKilled):
+        (WTF::MessageQueue<DataType>::removeIf):
+        (WTF::MessageQueue<DataType>::isEmpty):
+        (WTF::MessageQueue<DataType>::kill):
+        (WTF::MessageQueue<DataType>::killed const):
+        * wtf/OSLogPrintStream.cpp:
+        (WTF::OSLogPrintStream::vprintf):
+        * wtf/OSLogPrintStream.h:
+        * wtf/ParallelJobsGeneric.h:
+        (WTF::ParallelEnvironment::ThreadPrivate::WTF_GUARDED_BY_LOCK):
+        * wtf/ParallelVectorIterator.h:
+        (WTF::ParallelVectorIterator::iterate):
+        (WTF::ParallelVectorIterator::WTF_GUARDED_BY_LOCK):
+        * wtf/ReadWriteLock.cpp:
+        (WTF::ReadWriteLock::readLock):
+        (WTF::ReadWriteLock::readUnlock):
+        (WTF::ReadWriteLock::writeLock):
+        (WTF::ReadWriteLock::writeUnlock):
+        * wtf/ReadWriteLock.h:
+        (WTF::ReadWriteLock::WTF_GUARDED_BY_LOCK):
+
+2021-05-20  Chris Dumez  <[email protected]>
+
         Add missing locks in Language.cpp
         https://bugs.webkit.org/show_bug.cgi?id=226059
 

Modified: trunk/Source/WTF/wtf/CrossThreadQueue.h (277846 => 277847)


--- trunk/Source/WTF/wtf/CrossThreadQueue.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/CrossThreadQueue.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -27,7 +27,8 @@
 
 #include <limits>
 #include <wtf/Assertions.h>
-#include <wtf/Condition.h>
+#include <wtf/CheckedCondition.h>
+#include <wtf/CheckedLock.h>
 #include <wtf/Deque.h>
 #include <wtf/Lock.h>
 #include <wtf/Noncopyable.h>
@@ -52,16 +53,16 @@
     bool isEmpty() const;
 
 private:
-    Deque<DataType> m_queue;
-    mutable Lock m_lock;
-    Condition m_condition;
-    bool m_killed { false };
+    mutable CheckedLock m_lock;
+    Deque<DataType> m_queue WTF_GUARDED_BY_LOCK(m_lock);
+    CheckedCondition m_condition;
+    bool m_killed WTF_GUARDED_BY_LOCK(m_lock) { false };
 };
 
 template<typename DataType>
 void CrossThreadQueue<DataType>::append(DataType&& message)
 {
-    LockHolder lock(m_lock);
+    Locker locker { m_lock };
     ASSERT(!m_killed);
     m_queue.append(WTFMove(message));
     m_condition.notifyOne();
@@ -70,7 +71,7 @@
 template<typename DataType>
 DataType CrossThreadQueue<DataType>::waitForMessage()
 {
-    LockHolder lock(m_lock);
+    Locker locker { m_lock };
 
     auto found = m_queue.end();
     while (found == m_queue.end()) {
@@ -89,7 +90,7 @@
 template<typename DataType>
 Optional<DataType> CrossThreadQueue<DataType>::tryGetMessage()
 {
-    LockHolder lock(m_lock);
+    Locker locker { m_lock };
 
     if (m_queue.isEmpty())
         return { };
@@ -100,7 +101,7 @@
 template<typename DataType>
 void CrossThreadQueue<DataType>::kill()
 {
-    LockHolder lock(m_lock);
+    Locker locker { m_lock };
     m_killed = true;
     m_condition.notifyAll();
 }
@@ -108,7 +109,7 @@
 template<typename DataType>
 bool CrossThreadQueue<DataType>::isKilled() const
 {
-    LockHolder lock(m_lock);
+    Locker locker { m_lock };
     return m_killed;
 }
 
@@ -115,7 +116,7 @@
 template<typename DataType>
 bool CrossThreadQueue<DataType>::isEmpty() const
 {
-    LockHolder lock(m_lock);
+    Locker locker { m_lock };
     return m_queue.isEmpty();
 }
 

Modified: trunk/Source/WTF/wtf/CrossThreadTaskHandler.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/CrossThreadTaskHandler.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/CrossThreadTaskHandler.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -57,7 +57,7 @@
 {
     m_taskReplyQueue.append(WTFMove(task));
 
-    Locker<Lock> locker(m_mainThreadReplyLock);
+    Locker locker { m_mainThreadReplyLock };
     if (m_mainThreadReplyScheduled)
         return;
 
@@ -84,7 +84,7 @@
 void CrossThreadTaskHandler::handleTaskRepliesOnMainThread()
 {
     {
-        Locker<Lock> locker(m_mainThreadReplyLock);
+        Locker locker { m_mainThreadReplyLock };
         m_mainThreadReplyScheduled = false;
     }
 

Modified: trunk/Source/WTF/wtf/CrossThreadTaskHandler.h (277846 => 277847)


--- trunk/Source/WTF/wtf/CrossThreadTaskHandler.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/CrossThreadTaskHandler.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -25,9 +25,9 @@
 
 #pragma once
 
+#include <wtf/CheckedLock.h>
 #include <wtf/CrossThreadQueue.h>
 #include <wtf/CrossThreadTask.h>
-#include <wtf/Lock.h>
 #include <wtf/Threading.h>
 
 namespace WTF {
@@ -56,8 +56,8 @@
     AutodrainedPoolForRunLoop m_useAutodrainedPool { AutodrainedPoolForRunLoop::DoNotUse };
 
     Lock m_taskThreadCreationLock;
-    Lock m_mainThreadReplyLock;
-    bool m_mainThreadReplyScheduled { false };
+    CheckedLock m_mainThreadReplyLock;
+    bool m_mainThreadReplyScheduled WTF_GUARDED_BY_LOCK(m_mainThreadReplyLock) { false };
 
     CrossThreadQueue<CrossThreadTask> m_taskQueue;
     CrossThreadQueue<CrossThreadTask> m_taskReplyQueue;

Modified: trunk/Source/WTF/wtf/CryptographicallyRandomNumber.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/CryptographicallyRandomNumber.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/CryptographicallyRandomNumber.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -31,7 +31,7 @@
 #include <wtf/CryptographicallyRandomNumber.h>
 
 #include <mutex>
-#include <wtf/Lock.h>
+#include <wtf/CheckedLock.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/OSRandomSource.h>
 
@@ -59,14 +59,14 @@
 
 private:
     inline void addRandomData(unsigned char *data, int length);
-    void stir();
-    void stirIfNeeded();
+    void stir() WTF_REQUIRES_LOCK(m_lock);
+    void stirIfNeeded() WTF_REQUIRES_LOCK(m_lock);
     inline uint8_t getByte();
     inline uint32_t getWord();
 
+    CheckedLock m_lock;
     ARC4Stream m_stream;
     int m_count;
-    Lock m_mutex;
 };
 
 ARC4Stream::ARC4Stream()
@@ -138,7 +138,7 @@
 
 uint32_t ARC4RandomNumberGenerator::randomNumber()
 {
-    auto locker = holdLock(m_mutex);
+    Locker locker { m_lock };
 
     m_count -= 4;
     stirIfNeeded();
@@ -147,7 +147,7 @@
 
 void ARC4RandomNumberGenerator::randomValues(void* buffer, size_t length)
 {
-    auto locker = holdLock(m_mutex);
+    Locker locker { m_lock };
 
     unsigned char* result = reinterpret_cast<unsigned char*>(buffer);
     stirIfNeeded();

Modified: trunk/Source/WTF/wtf/FastMalloc.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/FastMalloc.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/FastMalloc.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -39,8 +39,8 @@
 
 #if ENABLE(MALLOC_HEAP_BREAKDOWN)
 #include <wtf/Atomics.h>
+#include <wtf/CheckedLock.h>
 #include <wtf/HashMap.h>
-#include <wtf/Lock.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/SetForScope.h>
 #include <wtf/StackShot.h>
@@ -376,8 +376,8 @@
         }
     };
 
-    HashMap<void*, std::unique_ptr<MallocSiteData>> m_addressMallocSiteData;
-    Lock m_mutex;
+    CheckedLock m_lock;
+    HashMap<void*, std::unique_ptr<MallocSiteData>> m_addressMallocSiteData WTF_GUARDED_BY_LOCK(m_lock);
 };
 
 MallocCallTracker& MallocCallTracker::singleton()
@@ -408,7 +408,7 @@
     const size_t stackSize = 10;
     auto siteData = std::make_unique<MallocSiteData>(stackSize, allocationSize);
 
-    auto locker = holdLock(m_mutex);
+    Locker locker { m_lock };
     auto addResult = m_addressMallocSiteData.add(address, WTFMove(siteData));
     UNUSED_PARAM(addResult);
 }
@@ -417,7 +417,7 @@
 {
     AvoidRecordingScope avoidRecording;
 
-    auto locker = holdLock(m_mutex);
+    Locker locker { m_lock };
 
     auto it = m_addressMallocSiteData.find(oldAddress);
     if (it == m_addressMallocSiteData.end()) {
@@ -438,7 +438,7 @@
 {
     AvoidRecordingScope avoidRecording;
 
-    auto locker = holdLock(m_mutex);
+    Locker locker { m_lock };
     bool removed = m_addressMallocSiteData.remove(address);
     UNUSED_PARAM(removed);
 }
@@ -448,7 +448,7 @@
     AvoidRecordingScope avoidRecording;
 
     {
-        auto locker = holdLock(m_mutex);
+        Locker locker { m_lock };
 
         // Build a hash of stack to address vector
         struct MallocSiteTotals {

Modified: trunk/Source/WTF/wtf/MessageQueue.h (277846 => 277847)


--- trunk/Source/WTF/wtf/MessageQueue.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/MessageQueue.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -31,9 +31,9 @@
 
 #include <limits>
 #include <wtf/Assertions.h>
-#include <wtf/Condition.h>
+#include <wtf/CheckedCondition.h>
+#include <wtf/CheckedLock.h>
 #include <wtf/Deque.h>
-#include <wtf/Lock.h>
 #include <wtf/MonotonicTime.h>
 #include <wtf/Noncopyable.h>
 
@@ -78,10 +78,10 @@
         bool isEmpty();
 
     private:
-        mutable Lock m_mutex;
-        Condition m_condition;
-        Deque<std::unique_ptr<DataType>> m_queue;
-        bool m_killed;
+        mutable CheckedLock m_lock;
+        CheckedCondition m_condition;
+        Deque<std::unique_ptr<DataType>> m_queue WTF_GUARDED_BY_LOCK(m_lock);
+        bool m_killed WTF_GUARDED_BY_LOCK(m_lock);
     };
 
     template<typename DataType>
@@ -92,7 +92,7 @@
     template<typename DataType>
     inline void MessageQueue<DataType>::append(std::unique_ptr<DataType> message)
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         m_queue.append(WTFMove(message));
         m_condition.notifyOne();
     }
@@ -100,7 +100,7 @@
     template<typename DataType>
     inline void MessageQueue<DataType>::appendAndKill(std::unique_ptr<DataType> message)
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         m_queue.append(WTFMove(message));
         m_killed = true;
         m_condition.notifyAll();
@@ -110,7 +110,7 @@
     template<typename DataType>
     inline bool MessageQueue<DataType>::appendAndCheckEmpty(std::unique_ptr<DataType> message)
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         bool wasEmpty = m_queue.isEmpty();
         m_queue.append(WTFMove(message));
         m_condition.notifyOne();
@@ -120,7 +120,7 @@
     template<typename DataType>
     inline void MessageQueue<DataType>::prepend(std::unique_ptr<DataType> message)
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         m_queue.prepend(WTFMove(message));
         m_condition.notifyOne();
     }
@@ -138,7 +138,7 @@
     template<typename Predicate>
     inline auto MessageQueue<DataType>::waitForMessageFilteredWithTimeout(MessageQueueWaitResult& result, Predicate&& predicate, Seconds relativeTimeout) -> std::unique_ptr<DataType>
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         bool timedOut = false;
 
         MonotonicTime absoluteTimeout = MonotonicTime::now() + relativeTimeout;
@@ -151,7 +151,7 @@
             if (found != m_queue.end())
                 break;
 
-            timedOut = !m_condition.waitUntil(m_mutex, absoluteTimeout);
+            timedOut = !m_condition.waitUntil(m_lock, absoluteTimeout);
         }
 
         ASSERT(!timedOut || absoluteTimeout != MonotonicTime::infinity());
@@ -176,7 +176,7 @@
     template<typename DataType>
     inline auto MessageQueue<DataType>::tryGetMessage() -> std::unique_ptr<DataType>
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         if (m_killed)
             return nullptr;
         if (m_queue.isEmpty())
@@ -188,7 +188,7 @@
     template<typename DataType>
     inline auto MessageQueue<DataType>::takeAllMessages() -> Deque<std::unique_ptr<DataType>>
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         if (m_killed)
             return { };
         return WTFMove(m_queue);
@@ -197,7 +197,7 @@
     template<typename DataType>
     inline auto MessageQueue<DataType>::tryGetMessageIgnoringKilled() -> std::unique_ptr<DataType>
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         if (m_queue.isEmpty())
             return nullptr;
 
@@ -208,7 +208,7 @@
     template<typename Predicate>
     inline void MessageQueue<DataType>::removeIf(Predicate&& predicate)
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         while (true) {
             auto found = m_queue.findIf([&predicate](const std::unique_ptr<DataType>& ptr) -> bool {
                 ASSERT(ptr);
@@ -225,7 +225,7 @@
     template<typename DataType>
     inline bool MessageQueue<DataType>::isEmpty()
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         if (m_killed)
             return true;
         return m_queue.isEmpty();
@@ -234,7 +234,7 @@
     template<typename DataType>
     inline void MessageQueue<DataType>::kill()
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         m_killed = true;
         m_condition.notifyAll();
     }
@@ -242,7 +242,7 @@
     template<typename DataType>
     inline bool MessageQueue<DataType>::killed() const
     {
-        LockHolder lock(m_mutex);
+        Locker lock { m_lock };
         return m_killed;
     }
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/OSLogPrintStream.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/OSLogPrintStream.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/OSLogPrintStream.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -48,7 +48,7 @@
 
 void OSLogPrintStream::vprintf(const char* format, va_list argList)
 {
-    auto lock = holdLock(m_stringLock);
+    Locker lock { m_stringLock };
     size_t offset = m_offset;
     size_t freeBytes = m_string.length() - offset;
     va_list backup;

Modified: trunk/Source/WTF/wtf/OSLogPrintStream.h (277846 => 277847)


--- trunk/Source/WTF/wtf/OSLogPrintStream.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/OSLogPrintStream.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -27,7 +27,7 @@
 
 #if OS(DARWIN)
 
-#include <wtf/Lock.h>
+#include <wtf/CheckedLock.h>
 #include <wtf/PrintStream.h>
 #include <wtf/RecursiveLockAdapter.h>
 #include <wtf/text/CString.h>
@@ -49,9 +49,9 @@
 private:
     os_log_t m_log;
     os_log_type_t m_logType;
-    Lock m_stringLock;
+    CheckedLock m_stringLock;
     // We need a buffer because os_log doesn't wait for a new line to print the characters.
-    CString m_string;
+    CString m_string WTF_GUARDED_BY_LOCK(m_stringLock);
     size_t m_offset { 0 };
 };
 

Modified: trunk/Source/WTF/wtf/ParallelJobsGeneric.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/ParallelJobsGeneric.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/ParallelJobsGeneric.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -83,19 +83,19 @@
 
 bool ParallelEnvironment::ThreadPrivate::tryLockFor(ParallelEnvironment* parent)
 {
-    bool locked = m_mutex.tryLock();
+    bool locked = m_lock.tryLock();
 
     if (!locked)
         return false;
 
     if (m_parent) {
-        m_mutex.unlock();
+        m_lock.unlock();
         return false;
     }
 
     if (!m_thread) {
         m_thread = Thread::create("Parallel worker", [this] {
-            LockHolder lock(m_mutex);
+            Locker lock { m_lock };
 
             while (true) {
                 if (m_running) {
@@ -105,19 +105,19 @@
                     m_threadCondition.notifyOne();
                 }
 
-                m_threadCondition.wait(m_mutex);
+                m_threadCondition.wait(m_lock);
             }
         });
     }
     m_parent = parent;
 
-    m_mutex.unlock();
+    m_lock.unlock();
     return true;
 }
 
 void ParallelEnvironment::ThreadPrivate::execute(ThreadFunction threadFunction, void* parameters)
 {
-    LockHolder lock(m_mutex);
+    Locker lock { m_lock };
 
     m_threadFunction = threadFunction;
     m_parameters = parameters;
@@ -127,10 +127,10 @@
 
 void ParallelEnvironment::ThreadPrivate::waitForFinish()
 {
-    LockHolder lock(m_mutex);
+    Locker lock { m_lock };
 
     while (m_running)
-        m_threadCondition.wait(m_mutex);
+        m_threadCondition.wait(m_lock);
 }
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/ParallelJobsGeneric.h (277846 => 277847)


--- trunk/Source/WTF/wtf/ParallelJobsGeneric.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/ParallelJobsGeneric.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -30,8 +30,8 @@
 
 #if ENABLE(THREADING_GENERIC)
 
-#include <wtf/Condition.h>
-#include <wtf/Lock.h>
+#include <wtf/CheckedCondition.h>
+#include <wtf/CheckedLock.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Threading.h>
 
@@ -65,13 +65,13 @@
         }
 
     private:
+        mutable CheckedLock m_lock;
+        CheckedCondition m_threadCondition;
+
         RefPtr<Thread> m_thread;
         bool m_running { false };
-        ParallelEnvironment* m_parent { nullptr };
+        ParallelEnvironment* m_parent WTF_GUARDED_BY_LOCK(m_lock) { nullptr };
 
-        mutable Lock m_mutex;
-        Condition m_threadCondition;
-
         ThreadFunction m_threadFunction { nullptr };
         void* m_parameters { nullptr };
     };

Modified: trunk/Source/WTF/wtf/ParallelVectorIterator.h (277846 => 277847)


--- trunk/Source/WTF/wtf/ParallelVectorIterator.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/ParallelVectorIterator.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -25,8 +25,8 @@
 
 #pragma once
 
+#include <wtf/CheckedLock.h>
 #include <wtf/FastMalloc.h>
-#include <wtf/Lock.h>
 #include <wtf/Noncopyable.h>
 
 namespace WTF {
@@ -49,7 +49,7 @@
             size_t begin;
             size_t end;
             {
-                LockHolder locker(m_lock);
+                Locker locker { m_lock };
                 begin = m_next;
                 if (begin == m_vector.size())
                     return;
@@ -67,10 +67,10 @@
         }
     }
 private:
-    VectorType& m_vector;
-    Lock m_lock;
-    size_t m_shardSize;
-    size_t m_next { 0 };
+    CheckedLock m_lock;
+    VectorType& m_vector WTF_GUARDED_BY_LOCK(m_lock);
+    size_t m_shardSize WTF_GUARDED_BY_LOCK(m_lock);
+    size_t m_next WTF_GUARDED_BY_LOCK(m_lock) { 0 };
 };
 
 } // namespace WTF

Modified: trunk/Source/WTF/wtf/ReadWriteLock.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/ReadWriteLock.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/ReadWriteLock.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -32,7 +32,7 @@
 
 void ReadWriteLock::readLock()
 {
-    auto locker = holdLock(m_lock);
+    Locker locker { m_lock };
     while (m_isWriteLocked || m_numWaitingWriters)
         m_cond.wait(m_lock);
     m_numReaders++;
@@ -40,7 +40,7 @@
 
 void ReadWriteLock::readUnlock()
 {
-    auto locker = holdLock(m_lock);
+    Locker locker { m_lock };
     m_numReaders--;
     if (!m_numReaders)
         m_cond.notifyAll();
@@ -48,7 +48,7 @@
 
 void ReadWriteLock::writeLock()
 {
-    auto locker = holdLock(m_lock);
+    Locker locker { m_lock };
     while (m_isWriteLocked || m_numReaders) {
         m_numWaitingWriters++;
         m_cond.wait(m_lock);
@@ -59,7 +59,7 @@
 
 void ReadWriteLock::writeUnlock()
 {
-    auto locker = holdLock(m_lock);
+    Locker locker { m_lock };
     m_isWriteLocked = false;
     m_cond.notifyAll();
 }

Modified: trunk/Source/WTF/wtf/ReadWriteLock.h (277846 => 277847)


--- trunk/Source/WTF/wtf/ReadWriteLock.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/ReadWriteLock.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -25,8 +25,8 @@
 
 #pragma once
 
-#include <wtf/Condition.h>
-#include <wtf/Lock.h>
+#include <wtf/CheckedCondition.h>
+#include <wtf/CheckedLock.h>
 
 namespace WTF {
 
@@ -61,11 +61,11 @@
     WriteLock& write();
 
 private:
-    Lock m_lock;
-    Condition m_cond;
-    bool m_isWriteLocked { false };
-    unsigned m_numReaders { 0 };
-    unsigned m_numWaitingWriters { 0 };
+    CheckedLock m_lock;
+    CheckedCondition m_cond;
+    bool m_isWriteLocked WTF_GUARDED_BY_LOCK(m_lock) { false };
+    unsigned m_numReaders WTF_GUARDED_BY_LOCK(m_lock) { 0 };
+    unsigned m_numWaitingWriters WTF_GUARDED_BY_LOCK(m_lock) { 0 };
 };
 
 class ReadWriteLock::ReadLock : public ReadWriteLock {

Modified: trunk/Source/WTF/wtf/RunLoop.cpp (277846 => 277847)


--- trunk/Source/WTF/wtf/RunLoop.cpp	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/RunLoop.cpp	2021-05-21 02:43:18 UTC (rev 277847)
@@ -114,7 +114,7 @@
     bool didSuspendFunctions = false;
 
     {
-        auto locker = holdLock(m_nextIterationLock);
+        Locker locker { m_nextIterationLock };
 
         // If the RunLoop re-enters or re-schedules, we're expected to execute all functions in order.
         while (!m_currentIteration.isEmpty())
@@ -146,7 +146,7 @@
     bool needsWakeup = false;
 
     {
-        auto locker = holdLock(m_nextIterationLock);
+        Locker locker { m_nextIterationLock };
         needsWakeup = m_nextIteration.isEmpty();
         m_nextIteration.append(WTFMove(function));
     }
@@ -180,7 +180,7 @@
 {
     m_currentIteration.clear();
     {
-        auto locker = holdLock(m_nextIterationLock);
+        Locker locker { m_nextIterationLock };
         m_nextIteration.clear();
     }
 }

Modified: trunk/Source/WTF/wtf/RunLoop.h (277846 => 277847)


--- trunk/Source/WTF/wtf/RunLoop.h	2021-05-21 02:37:42 UTC (rev 277846)
+++ trunk/Source/WTF/wtf/RunLoop.h	2021-05-21 02:43:18 UTC (rev 277847)
@@ -28,6 +28,7 @@
 #pragma once
 
 #include <functional>
+#include <wtf/CheckedLock.h>
 #include <wtf/Condition.h>
 #include <wtf/Deque.h>
 #include <wtf/Forward.h>
@@ -216,8 +217,8 @@
 
     Deque<Function<void()>> m_currentIteration;
 
-    Lock m_nextIterationLock;
-    Deque<Function<void()>> m_nextIteration;
+    CheckedLock m_nextIterationLock;
+    Deque<Function<void()>> m_nextIteration WTF_GUARDED_BY_LOCK(m_nextIterationLock);
 
     bool m_isFunctionDispatchSuspended { false };
     bool m_hasSuspendedFunctions { false };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to