From 83691374698dc3cdbe6651a4684d7a2d8cf6b09b 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 --- xpcom/threads/nsAutoLock.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/xpcom/threads/nsAutoLock.h b/xpcom/threads/nsAutoLock.h index a014b22dba49..4532d8a0ba1b 100644 --- a/xpcom/threads/nsAutoLock.h +++ b/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; } };