Title: [219179] trunk/Source
Revision
219179
Author
utatane....@gmail.com
Date
2017-07-05 19:27:06 -0700 (Wed, 05 Jul 2017)

Log Message

Use std::lock_guard instead of std::unique_lock if move semantics and try_lock is not necessary
https://bugs.webkit.org/show_bug.cgi?id=174148

Reviewed by Mark Lam.

Source/WebCore:

* platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
(WebCore::AudioSourceProviderAVFObjC::~AudioSourceProviderAVFObjC):

Source/WTF:

It is not necessary to use std::unique_lock if we do not use additional features compared to std::lock_guard.

(WTF::ThreadHolder::get):
(WTF::ThreadHolder::initialize):
(WTF::ThreadHolder::destruct):
* wtf/Threading.cpp:
(WTF::Thread::didExit):
* wtf/ThreadingPthreads.cpp:
(WTF::Thread::changePriority):
(WTF::Thread::waitForCompletion):
(WTF::Thread::detach):
(WTF::Thread::signal):
(WTF::Thread::resume):
(WTF::Thread::getRegisters):
(WTF::Thread::establish):
* wtf/ThreadingWin.cpp:
(WTF::Thread::changePriority):
(WTF::Thread::waitForCompletion):
(WTF::Thread::detach):
(WTF::Thread::resume):
(WTF::Thread::getRegisters):
(WTF::Thread::establish):
* wtf/WordLock.cpp:
(WTF::WordLockBase::unlockSlow):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (219178 => 219179)


--- trunk/Source/WTF/ChangeLog	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WTF/ChangeLog	2017-07-06 02:27:06 UTC (rev 219179)
@@ -1,5 +1,37 @@
 2017-07-05  Yusuke Suzuki  <utatane....@gmail.com>
 
+        Use std::lock_guard instead of std::unique_lock if move semantics and try_lock is not necessary
+        https://bugs.webkit.org/show_bug.cgi?id=174148
+
+        Reviewed by Mark Lam.
+
+        It is not necessary to use std::unique_lock if we do not use additional features compared to std::lock_guard.
+
+        (WTF::ThreadHolder::get):
+        (WTF::ThreadHolder::initialize):
+        (WTF::ThreadHolder::destruct):
+        * wtf/Threading.cpp:
+        (WTF::Thread::didExit):
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::Thread::changePriority):
+        (WTF::Thread::waitForCompletion):
+        (WTF::Thread::detach):
+        (WTF::Thread::signal):
+        (WTF::Thread::resume):
+        (WTF::Thread::getRegisters):
+        (WTF::Thread::establish):
+        * wtf/ThreadingWin.cpp:
+        (WTF::Thread::changePriority):
+        (WTF::Thread::waitForCompletion):
+        (WTF::Thread::detach):
+        (WTF::Thread::resume):
+        (WTF::Thread::getRegisters):
+        (WTF::Thread::establish):
+        * wtf/WordLock.cpp:
+        (WTF::WordLockBase::unlockSlow):
+
+2017-07-05  Yusuke Suzuki  <utatane....@gmail.com>
+
         [WTF] Clean up StringStatics.cpp by using LazyNeverDestroyed<> for Atoms
         https://bugs.webkit.org/show_bug.cgi?id=174150
 

Modified: trunk/Source/WTF/wtf/ThreadHolderWin.cpp (219178 => 219179)


--- trunk/Source/WTF/wtf/ThreadHolderWin.cpp	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WTF/wtf/ThreadHolderWin.cpp	2017-07-06 02:27:06 UTC (rev 219179)
@@ -66,7 +66,7 @@
     }
 
     // After FLS is destroyed, this map offers the value until the second thread exit callback is called.
-    std::unique_lock<std::mutex> locker(threadMapMutex());
+    std::lock_guard<std::mutex> locker(threadMapMutex());
     return threadMap().get(currentThread());
 }
 
@@ -73,7 +73,7 @@
 // FIXME: Remove this workaround code once <rdar://problem/31793213> is fixed.
 RefPtr<Thread> ThreadHolder::get(ThreadIdentifier id)
 {
-    std::unique_lock<std::mutex> locker(threadMapMutex());
+    std::lock_guard<std::mutex> locker(threadMapMutex());
     ThreadHolder* holder = threadMap().get(id);
     if (holder)
         return &holder->thread();
@@ -93,7 +93,7 @@
 
         // Since Thread is not established yet, we use the given id instead of thread->id().
         {
-            std::unique_lock<std::mutex> locker(threadMapMutex());
+            std::lock_guard<std::mutex> locker(threadMapMutex());
             threadMap().add(id, holder);
         }
     }
@@ -127,7 +127,7 @@
 
     if (holder->m_isDestroyedOnce) {
         {
-            std::unique_lock<std::mutex> locker(threadMapMutex());
+            std::lock_guard<std::mutex> locker(threadMapMutex());
             ASSERT(threadMap().contains(holder->m_thread->id()));
             threadMap().remove(holder->m_thread->id());
         }

Modified: trunk/Source/WTF/wtf/Threading.cpp (219178 => 219179)


--- trunk/Source/WTF/wtf/Threading.cpp	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WTF/wtf/Threading.cpp	2017-07-06 02:27:06 UTC (rev 219179)
@@ -132,7 +132,7 @@
 
 void Thread::didExit()
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     m_didExit = true;
 }
 

Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (219178 => 219179)


--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp	2017-07-06 02:27:06 UTC (rev 219179)
@@ -250,7 +250,7 @@
 
 void Thread::changePriority(int delta)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
 
     int policy;
     struct sched_param param;
@@ -267,7 +267,7 @@
 {
     pthread_t handle;
     {
-        std::unique_lock<std::mutex> locker(m_mutex);
+        std::lock_guard<std::mutex> locker(m_mutex);
         handle = m_handle;
     }
 
@@ -278,7 +278,7 @@
     else if (joinResult)
         LOG_ERROR("ThreadIdentifier %u was unable to be joined.\n", m_id);
 
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     ASSERT(joinableState() == Joinable);
 
     // If the thread has already exited, then do nothing. If the thread hasn't exited yet, then just signal that we've already joined on it.
@@ -291,7 +291,7 @@
 
 void Thread::detach()
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     int detachResult = pthread_detach(m_handle);
     if (detachResult)
         LOG_ERROR("ThreadIdentifier %u was unable to be detached\n", m_id);
@@ -320,7 +320,7 @@
 
 bool Thread::signal(int signalNumber)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     if (hasExited())
         return false;
     int errNo = pthread_kill(m_handle, signalNumber);
@@ -330,7 +330,7 @@
 auto Thread::suspend() -> Expected<void, PlatformSuspendError>
 {
     RELEASE_ASSERT_WITH_MESSAGE(id() != currentThread(), "We do not support suspending the current thread itself.");
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
 #if OS(DARWIN)
     kern_return_t result = thread_suspend(m_platformThread);
     if (result != KERN_SUCCESS)
@@ -365,7 +365,7 @@
 
 void Thread::resume()
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
 #if OS(DARWIN)
     thread_resume(m_platformThread);
 #else
@@ -427,7 +427,7 @@
 
 size_t Thread::getRegisters(PlatformRegisters& registers)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
 #if OS(DARWIN)
     auto metadata = threadStateMetadata();
     kern_return_t result = thread_get_state(m_platformThread, metadata.flavor, (thread_state_t)&registers, &metadata.userCount);
@@ -445,7 +445,7 @@
 
 void Thread::establish(pthread_t handle)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     m_handle = handle;
     if (!m_id) {
         static std::atomic<ThreadIdentifier> provider { 0 };

Modified: trunk/Source/WTF/wtf/ThreadingWin.cpp (219178 => 219179)


--- trunk/Source/WTF/wtf/ThreadingWin.cpp	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WTF/wtf/ThreadingWin.cpp	2017-07-06 02:27:06 UTC (rev 219179)
@@ -197,7 +197,7 @@
 
 void Thread::changePriority(int delta)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     SetThreadPriority(m_handle, THREAD_PRIORITY_NORMAL + delta);
 }
 
@@ -205,7 +205,7 @@
 {
     HANDLE handle;
     {
-        std::unique_lock<std::mutex> locker(m_mutex);
+        std::lock_guard<std::mutex> locker(m_mutex);
         handle = m_handle;
     }
 
@@ -213,7 +213,7 @@
     if (joinResult == WAIT_FAILED)
         LOG_ERROR("ThreadIdentifier %u was found to be deadlocked trying to quit", m_id);
 
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     ASSERT(joinableState() == Joinable);
 
     // The thread has already exited, do nothing.
@@ -235,7 +235,7 @@
     // FlsCallback automatically. FlsCallback will call CloseHandle to clean up
     // resource. So in this function, we just mark the thread as detached to
     // avoid calling waitForCompletion for this thread.
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     if (!hasExited())
         didBecomeDetached();
 }
@@ -243,7 +243,7 @@
 auto Thread::suspend() -> Expected<void, PlatformSuspendError>
 {
     RELEASE_ASSERT_WITH_MESSAGE(id() != currentThread(), "We do not support suspending the current thread itself.");
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     DWORD result = SuspendThread(m_handle);
     if (result != (DWORD)-1)
         return { };
@@ -253,13 +253,13 @@
 // During resume, suspend or resume should not be executed from the other threads.
 void Thread::resume()
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     ResumeThread(m_handle);
 }
 
 size_t Thread::getRegisters(PlatformRegisters& registers)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     registers.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL;
     GetThreadContext(m_handle, &registers);
     return sizeof(CONTEXT);
@@ -290,7 +290,7 @@
 
 void Thread::establish(HANDLE handle, ThreadIdentifier threadID)
 {
-    std::unique_lock<std::mutex> locker(m_mutex);
+    std::lock_guard<std::mutex> locker(m_mutex);
     m_handle = handle;
     m_id = threadID;
 }

Modified: trunk/Source/WTF/wtf/WordLock.cpp (219178 => 219179)


--- trunk/Source/WTF/wtf/WordLock.cpp	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WTF/wtf/WordLock.cpp	2017-07-06 02:27:06 UTC (rev 219179)
@@ -253,7 +253,7 @@
     // We do this carefully because this may run either before or during the parkingLock critical
     // section in lockSlow().
     {
-        std::unique_lock<std::mutex> locker(queueHead->parkingLock);
+        std::lock_guard<std::mutex> locker(queueHead->parkingLock);
         queueHead->shouldPark = false;
     }
     // Doesn't matter if we notify_all() or notify_one() here since the only thread that could be

Modified: trunk/Source/WebCore/ChangeLog (219178 => 219179)


--- trunk/Source/WebCore/ChangeLog	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WebCore/ChangeLog	2017-07-06 02:27:06 UTC (rev 219179)
@@ -1,5 +1,15 @@
 2017-07-05  Yusuke Suzuki  <utatane....@gmail.com>
 
+        Use std::lock_guard instead of std::unique_lock if move semantics and try_lock is not necessary
+        https://bugs.webkit.org/show_bug.cgi?id=174148
+
+        Reviewed by Mark Lam.
+
+        * platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm:
+        (WebCore::AudioSourceProviderAVFObjC::~AudioSourceProviderAVFObjC):
+
+2017-07-05  Yusuke Suzuki  <utatane....@gmail.com>
+
         [WTF] Clean up StringStatics.cpp by using LazyNeverDestroyed<> for Atoms
         https://bugs.webkit.org/show_bug.cgi?id=174150
 

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm (219178 => 219179)


--- trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm	2017-07-06 02:02:51 UTC (rev 219178)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/AudioSourceProviderAVFObjC.mm	2017-07-06 02:27:06 UTC (rev 219179)
@@ -93,7 +93,7 @@
 {
     setClient(nullptr);
     if (m_tapStorage) {
-        std::unique_lock<Lock> lock(m_tapStorage->mutex);
+        std::lock_guard<Lock> lock(m_tapStorage->mutex);
         m_tapStorage->_this = nullptr;
         m_tapStorage = nullptr;
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to