[WTF] Use static initializers for WTF::Mutex and WTF::ThreadCondition
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 May 2018 02:46:36 +0000 (02:46 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 7 May 2018 02:46:36 +0000 (02:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185361

Reviewed by Sam Weinig.

Use static initializers for WTF::Mutex and WTF::ThreadCondition to make
constructors of them simple and constexpr.

* wtf/ThreadingPrimitives.h:
* wtf/ThreadingPthreads.cpp:
(WTF::Mutex::Mutex): Deleted.
(WTF::ThreadCondition::ThreadCondition): Deleted.
* wtf/ThreadingWin.cpp:
(WTF::Mutex::Mutex): Deleted.
(WTF::ThreadCondition::ThreadCondition): Deleted.

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

Source/WTF/ChangeLog
Source/WTF/wtf/ThreadingPrimitives.h
Source/WTF/wtf/ThreadingPthreads.cpp
Source/WTF/wtf/ThreadingWin.cpp

index b2bea75..30fddee 100644 (file)
@@ -1,3 +1,21 @@
+2018-05-06  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] Use static initializers for WTF::Mutex and WTF::ThreadCondition
+        https://bugs.webkit.org/show_bug.cgi?id=185361
+
+        Reviewed by Sam Weinig.
+
+        Use static initializers for WTF::Mutex and WTF::ThreadCondition to make
+        constructors of them simple and constexpr.
+
+        * wtf/ThreadingPrimitives.h:
+        * wtf/ThreadingPthreads.cpp:
+        (WTF::Mutex::Mutex): Deleted.
+        (WTF::ThreadCondition::ThreadCondition): Deleted.
+        * wtf/ThreadingWin.cpp:
+        (WTF::Mutex::Mutex): Deleted.
+        (WTF::ThreadCondition::ThreadCondition): Deleted.
+
 2018-05-04  Tim Horton  <timothy_horton@apple.com>
 
         Shift to a lower-level framework for simplifying URLs
index fdf607f..7f20bc9 100644 (file)
@@ -65,7 +65,7 @@ class Mutex {
     WTF_MAKE_NONCOPYABLE(Mutex);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    WTF_EXPORT_PRIVATE Mutex();
+    constexpr Mutex() = default;
     WTF_EXPORT_PRIVATE ~Mutex();
 
     WTF_EXPORT_PRIVATE void lock();
@@ -75,7 +75,11 @@ public:
     PlatformMutex& impl() { return m_mutex; }
 
 private:
-    PlatformMutex m_mutex;
+#if USE(PTHREADS)
+    PlatformMutex m_mutex = PTHREAD_MUTEX_INITIALIZER;
+#elif OS(WINDOWS)
+    PlatformMutex m_mutex = SRWLOCK_INIT;
+#endif
 };
 
 typedef Locker<Mutex> MutexLocker;
@@ -84,7 +88,7 @@ class ThreadCondition {
     WTF_MAKE_NONCOPYABLE(ThreadCondition);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    WTF_EXPORT_PRIVATE ThreadCondition();
+    constexpr ThreadCondition() = default;
     WTF_EXPORT_PRIVATE ~ThreadCondition();
     
     WTF_EXPORT_PRIVATE void wait(Mutex& mutex);
@@ -94,7 +98,11 @@ public:
     WTF_EXPORT_PRIVATE void broadcast();
     
 private:
-    PlatformCondition m_condition;
+#if USE(PTHREADS)
+    PlatformCondition m_condition = PTHREAD_COND_INITIALIZER;
+#elif OS(WINDOWS)
+    PlatformCondition m_condition = CONDITION_VARIABLE_INIT;
+#endif
 };
 
 } // namespace WTF
index 80b1212..a3f428c 100644 (file)
@@ -490,18 +490,6 @@ void Thread::destructTLS(void* data)
 #endif
 }
 
-Mutex::Mutex()
-{
-    pthread_mutexattr_t attr;
-    pthread_mutexattr_init(&attr);
-    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
-
-    int result = pthread_mutex_init(&m_mutex, &attr);
-    ASSERT_UNUSED(result, !result);
-
-    pthread_mutexattr_destroy(&attr);
-}
-
 Mutex::~Mutex()
 {
     int result = pthread_mutex_destroy(&m_mutex);
@@ -533,11 +521,6 @@ void Mutex::unlock()
     ASSERT_UNUSED(result, !result);
 }
 
-ThreadCondition::ThreadCondition()
-{ 
-    pthread_cond_init(&m_condition, NULL);
-}
-
 ThreadCondition::~ThreadCondition()
 {
     pthread_cond_destroy(&m_condition);
index 4e65a5e..e1ae74e 100644 (file)
@@ -360,11 +360,6 @@ void Thread::destructTLS(void* data)
     thread->m_isDestroyedOnce = true;
 }
 
-Mutex::Mutex()
-{
-    InitializeSRWLock(&m_mutex);
-}
-
 Mutex::~Mutex()
 {
 }
@@ -400,11 +395,6 @@ static DWORD absoluteTimeToWaitTimeoutInterval(WallTime absoluteTime)
     return static_cast<DWORD>((absoluteTime - currentTime).milliseconds());
 }
 
-ThreadCondition::ThreadCondition()
-{
-    InitializeConditionVariable(&m_condition);
-}
-
 ThreadCondition::~ThreadCondition()
 {
 }