From b34e6f5815ab838667a77bfcd1d59794c54c58ac Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Tue, 22 Sep 2015 19:26:21 +0200 Subject: [PATCH] Bug 1207232: Let lockOwner be Atomic; r=terrence --HG-- extra : commitid : FFrGdIRgTdY extra : rebase_source : c04b2c8ed994fd3d74f3a4467015199d03e130ee --- js/src/gc/GCRuntime.h | 14 ++++++++------ js/src/jsgc.cpp | 5 ++--- js/src/vm/HelperThreads.cpp | 13 +++++-------- js/src/vm/HelperThreads.h | 4 +--- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/js/src/gc/GCRuntime.h b/js/src/gc/GCRuntime.h index c7376b22a4f0..e9521ce09e3c 100644 --- a/js/src/gc/GCRuntime.h +++ b/js/src/gc/GCRuntime.h @@ -673,7 +673,7 @@ class GCRuntime bool onBackgroundThread() { return helperState.onBackgroundThread(); } bool currentThreadOwnsGCLock() { - return lockOwner == PR_GetCurrentThread(); + return lockOwner.value == PR_GetCurrentThread(); } #endif // DEBUG @@ -684,15 +684,17 @@ class GCRuntime void lockGC() { PR_Lock(lock); - MOZ_ASSERT(!lockOwner); #ifdef DEBUG - lockOwner = PR_GetCurrentThread(); + MOZ_ASSERT(!lockOwner.value); + lockOwner.value = PR_GetCurrentThread(); #endif } void unlockGC() { - MOZ_ASSERT(lockOwner == PR_GetCurrentThread()); - lockOwner = nullptr; +#ifdef DEBUG + MOZ_ASSERT(lockOwner.value == PR_GetCurrentThread()); + lockOwner.value = nullptr; +#endif PR_Unlock(lock); } @@ -1298,7 +1300,7 @@ class GCRuntime /* Synchronize GC heap access between main thread and GCHelperState. */ PRLock* lock; - mozilla::DebugOnly lockOwner; + mozilla::DebugOnly> lockOwner; BackgroundAllocTask allocTask; GCHelperState helperState; diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index e12a7d8b913c..f945eb60bf61 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -1176,7 +1176,6 @@ GCRuntime::GCRuntime(JSRuntime* rt) : noGCOrAllocationCheck(0), #endif lock(nullptr), - lockOwner(nullptr), allocTask(rt, emptyChunks_), helperState(rt) { @@ -3409,11 +3408,11 @@ GCHelperState::waitForBackgroundThread() MOZ_ASSERT(CurrentThreadCanAccessRuntime(rt)); #ifdef DEBUG - rt->gc.lockOwner = nullptr; + rt->gc.lockOwner.value = nullptr; #endif PR_WaitCondVar(done, PR_INTERVAL_NO_TIMEOUT); #ifdef DEBUG - rt->gc.lockOwner = PR_GetCurrentThread(); + rt->gc.lockOwner.value = PR_GetCurrentThread(); #endif } diff --git a/js/src/vm/HelperThreads.cpp b/js/src/vm/HelperThreads.cpp index 37a0988d2735..6c6cc9fe73ad 100644 --- a/js/src/vm/HelperThreads.cpp +++ b/js/src/vm/HelperThreads.cpp @@ -492,9 +492,6 @@ GlobalHelperThreadState::GlobalHelperThreadState() threads(nullptr), asmJSCompilationInProgress(false), helperLock(nullptr), -#ifdef DEBUG - lockOwner(nullptr), -#endif consumerWakeup(nullptr), producerWakeup(nullptr), pauseWakeup(nullptr), @@ -545,7 +542,7 @@ GlobalHelperThreadState::lock() AssertCurrentThreadCanLock(HelperThreadStateLock); PR_Lock(helperLock); #ifdef DEBUG - lockOwner = PR_GetCurrentThread(); + lockOwner.value = PR_GetCurrentThread(); #endif } @@ -554,7 +551,7 @@ GlobalHelperThreadState::unlock() { MOZ_ASSERT(isLocked()); #ifdef DEBUG - lockOwner = nullptr; + lockOwner.value = nullptr; #endif PR_Unlock(helperLock); } @@ -563,7 +560,7 @@ GlobalHelperThreadState::unlock() bool GlobalHelperThreadState::isLocked() { - return lockOwner == PR_GetCurrentThread(); + return lockOwner.value == PR_GetCurrentThread(); } #endif @@ -572,14 +569,14 @@ GlobalHelperThreadState::wait(CondVar which, uint32_t millis) { MOZ_ASSERT(isLocked()); #ifdef DEBUG - lockOwner = nullptr; + lockOwner.value = nullptr; #endif DebugOnly status = PR_WaitCondVar(whichWakeup(which), millis ? PR_MillisecondsToInterval(millis) : PR_INTERVAL_NO_TIMEOUT); MOZ_ASSERT(status == PR_SUCCESS); #ifdef DEBUG - lockOwner = PR_GetCurrentThread(); + lockOwner.value = PR_GetCurrentThread(); #endif } diff --git a/js/src/vm/HelperThreads.h b/js/src/vm/HelperThreads.h index 30fcfc49371d..0c22485f43a5 100644 --- a/js/src/vm/HelperThreads.h +++ b/js/src/vm/HelperThreads.h @@ -242,9 +242,7 @@ class GlobalHelperThreadState * used by all condition variables. */ PRLock* helperLock; -#ifdef DEBUG - PRThread* lockOwner; -#endif + mozilla::DebugOnly> lockOwner; /* Condvars for threads waiting/notifying each other. */ PRCondVar* consumerWakeup;