Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1453)

Unified Diff: Source/wtf/ThreadingPthreads.cpp

Issue 415083002: [oilpan]: fix deadlock when leaving a safepoint and sweeping. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/wtf/ThreadingPthreads.cpp
diff --git a/Source/wtf/ThreadingPthreads.cpp b/Source/wtf/ThreadingPthreads.cpp
index afa5993840a88a44082c390c56aba6c0f8a79362..52feef44078e486e11dbb9cbfd9bededc121bef4 100644
--- a/Source/wtf/ThreadingPthreads.cpp
+++ b/Source/wtf/ThreadingPthreads.cpp
@@ -289,36 +289,63 @@ ThreadIdentifier currentThread()
return id;
}
-Mutex::Mutex()
+MutexBase::MutexBase(bool recursive)
{
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL);
+ pthread_mutexattr_settype(&attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL);
- int result = pthread_mutex_init(&m_mutex, &attr);
+ int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr);
ASSERT_UNUSED(result, !result);
+#ifndef NDEBUG
tkent 2014/07/25 05:11:44 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:28 Done.
+ m_mutex.m_recursionCount = 0;
+#endif
pthread_mutexattr_destroy(&attr);
}
-Mutex::~Mutex()
+MutexBase::~MutexBase()
{
- int result = pthread_mutex_destroy(&m_mutex);
+ int result = pthread_mutex_destroy(&m_mutex.m_internalMutex);
ASSERT_UNUSED(result, !result);
}
-void Mutex::lock()
+void MutexBase::lock()
{
- int result = pthread_mutex_lock(&m_mutex);
+ int result = pthread_mutex_lock(&m_mutex.m_internalMutex);
ASSERT_UNUSED(result, !result);
+#ifndef NDEBUG
tkent 2014/07/25 05:11:44 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:28 Done.
+ ++m_mutex.m_recursionCount;
+#endif
}
-bool Mutex::tryLock()
+void MutexBase::unlock()
{
- int result = pthread_mutex_trylock(&m_mutex);
+#ifndef NDEBUG
tkent 2014/07/25 05:11:45 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:29 Done.
+ ASSERT(m_mutex.m_recursionCount);
+ --m_mutex.m_recursionCount;
+#endif
+ int result = pthread_mutex_unlock(&m_mutex.m_internalMutex);
+ ASSERT_UNUSED(result, !result);
+}
- if (result == 0)
+// There is a separate tryLock implementation for the Mutex and the
+// RecursiveMutex since on Windows we need to manually check if tryLock should
+// succeed or not for the non-recursive mutex. On Linux the two implementations
Erik Corry 2014/07/25 10:32:37 On pthreads the two...
+// are equal except we can assert the recursion count is always zero for the
+// non-recursive mutex.
+bool Mutex::tryLock()
+{
+ int result = pthread_mutex_trylock(&m_mutex.m_internalMutex);
+ if (result == 0) {
+#ifndef NDEBUG
tkent 2014/07/25 05:11:44 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:28 Done.
+ // The Mutex class is not recursive, so the recursionCount should be
+ // zero after getting the lock.
+ ASSERT(!m_mutex.m_recursionCount);
+ ++m_mutex.m_recursionCount;
+#endif
return true;
+ }
if (result == EBUSY)
return false;
@@ -326,10 +353,20 @@ bool Mutex::tryLock()
return false;
}
-void Mutex::unlock()
+bool RecursiveMutex::tryLock()
{
- int result = pthread_mutex_unlock(&m_mutex);
- ASSERT_UNUSED(result, !result);
+ int result = pthread_mutex_trylock(&m_mutex.m_internalMutex);
+ if (result == 0) {
+#ifndef NDEBUG
tkent 2014/07/25 05:11:44 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:28 Done.
+ ++m_mutex.m_recursionCount;
+#endif
+ return true;
+ }
+ if (result == EBUSY)
+ return false;
+
+ ASSERT_NOT_REACHED();
+ return false;
}
ThreadCondition::ThreadCondition()
@@ -342,13 +379,17 @@ ThreadCondition::~ThreadCondition()
pthread_cond_destroy(&m_condition);
}
-void ThreadCondition::wait(Mutex& mutex)
+void ThreadCondition::wait(MutexBase& mutex)
{
- int result = pthread_cond_wait(&m_condition, &mutex.impl());
+ PlatformMutex& platformMutex = mutex.impl();
+ int result = pthread_cond_wait(&m_condition, &platformMutex.m_internalMutex);
ASSERT_UNUSED(result, !result);
+#ifndef NDEBUG
tkent 2014/07/25 05:11:44 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:28 Done.
+ ++platformMutex.m_recursionCount;
+#endif
}
-bool ThreadCondition::timedWait(Mutex& mutex, double absoluteTime)
+bool ThreadCondition::timedWait(MutexBase& mutex, double absoluteTime)
{
if (absoluteTime < currentTime())
return false;
@@ -365,7 +406,12 @@ bool ThreadCondition::timedWait(Mutex& mutex, double absoluteTime)
targetTime.tv_sec = timeSeconds;
targetTime.tv_nsec = timeNanoseconds;
- return pthread_cond_timedwait(&m_condition, &mutex.impl(), &targetTime) == 0;
+ PlatformMutex& platformMutex = mutex.impl();
+ int result = pthread_cond_timedwait(&m_condition, &platformMutex.m_internalMutex, &targetTime);
+#ifndef NDEBUG
tkent 2014/07/25 05:11:44 #if ENABLE(ASSERT)
wibling-chromium 2014/07/25 09:31:29 Done.
+ ++platformMutex.m_recursionCount;
+#endif
+ return result == 0;
}
void ThreadCondition::signal()

Powered by Google App Engine
This is Rietveld 408576698