From ee57201b52bf4ae90d04cd328dd6d0b2aac73ed3 Mon Sep 17 00:00:00 2001 From: "jband%netscape.com" Date: Mon, 15 Nov 1999 22:15:27 +0000 Subject: [PATCH] r=waterson. add explicit lock and unlock to nsAutoLock. This allows us to use the autolock to cover a scope and to also explicitly bracket a call out to some other function with an unlock and relock git-svn-id: svn://10.0.0.236/trunk@53551 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/threads/nsAutoLock.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mozilla/xpcom/threads/nsAutoLock.h b/mozilla/xpcom/threads/nsAutoLock.h index a014b22dba4..4532d8a0ba1 100644 --- a/mozilla/xpcom/threads/nsAutoLock.h +++ b/mozilla/xpcom/threads/nsAutoLock.h @@ -102,6 +102,7 @@ protected: class NS_COM nsAutoLock : public nsAutoLockBase { private: PRLock* mLock; + PRBool mLocked; // Not meant to be implemented. This makes it a compiler error to // construct or assign an nsAutoLock object incorrectly. @@ -125,7 +126,8 @@ private: public: nsAutoLock(PRLock* aLock) : nsAutoLockBase(aLock, eAutoLock), - mLock(aLock) { + mLock(aLock), + mLocked(PR_TRUE) { PR_ASSERT(mLock); // This will assert deep in the bowels of NSPR if you attempt @@ -134,7 +136,20 @@ public: } ~nsAutoLock(void) { + if (mLocked) + PR_Unlock(mLock); + } + + void lock() { + PR_ASSERT(!mLocked); + PR_Lock(mLock); + mLocked = PR_TRUE; + } + + void unlock() { + PR_ASSERT(mLocked); PR_Unlock(mLock); + mLocked = PR_FALSE; } };