зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
4fffbc4bf8
Коммит
8369137469
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче