Title: [231402] trunk/Source/WTF
- Revision
- 231402
- Author
- [email protected]
- Date
- 2018-05-06 19:46:36 -0700 (Sun, 06 May 2018)
Log Message
[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.
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (231401 => 231402)
--- trunk/Source/WTF/ChangeLog 2018-05-07 02:09:16 UTC (rev 231401)
+++ trunk/Source/WTF/ChangeLog 2018-05-07 02:46:36 UTC (rev 231402)
@@ -1,3 +1,21 @@
+2018-05-06 Yusuke Suzuki <[email protected]>
+
+ [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 <[email protected]>
Shift to a lower-level framework for simplifying URLs
Modified: trunk/Source/WTF/wtf/ThreadingPrimitives.h (231401 => 231402)
--- trunk/Source/WTF/wtf/ThreadingPrimitives.h 2018-05-07 02:09:16 UTC (rev 231401)
+++ trunk/Source/WTF/wtf/ThreadingPrimitives.h 2018-05-07 02:46:36 UTC (rev 231402)
@@ -65,7 +65,7 @@
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 @@
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 @@
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 @@
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
Modified: trunk/Source/WTF/wtf/ThreadingPthreads.cpp (231401 => 231402)
--- trunk/Source/WTF/wtf/ThreadingPthreads.cpp 2018-05-07 02:09:16 UTC (rev 231401)
+++ trunk/Source/WTF/wtf/ThreadingPthreads.cpp 2018-05-07 02:46:36 UTC (rev 231402)
@@ -490,18 +490,6 @@
#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 @@
ASSERT_UNUSED(result, !result);
}
-ThreadCondition::ThreadCondition()
-{
- pthread_cond_init(&m_condition, NULL);
-}
-
ThreadCondition::~ThreadCondition()
{
pthread_cond_destroy(&m_condition);
Modified: trunk/Source/WTF/wtf/ThreadingWin.cpp (231401 => 231402)
--- trunk/Source/WTF/wtf/ThreadingWin.cpp 2018-05-07 02:09:16 UTC (rev 231401)
+++ trunk/Source/WTF/wtf/ThreadingWin.cpp 2018-05-07 02:46:36 UTC (rev 231402)
@@ -360,11 +360,6 @@
thread->m_isDestroyedOnce = true;
}
-Mutex::Mutex()
-{
- InitializeSRWLock(&m_mutex);
-}
-
Mutex::~Mutex()
{
}
@@ -400,11 +395,6 @@
return static_cast<DWORD>((absoluteTime - currentTime).milliseconds());
}
-ThreadCondition::ThreadCondition()
-{
- InitializeConditionVariable(&m_condition);
-}
-
ThreadCondition::~ThreadCondition()
{
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes