Bug 1374594 - Allow mutex/monitor scoped unlockers to be constructed from their locking counterparts - r=froydnj

MozReview-Commit-ID: 7PResfLcEeO

--HG--
extra : rebase_source : aab88391ef689bf92742a0ef37729d664dd528b3
This commit is contained in:
Gerald Squelart 2017-06-20 22:20:49 +12:00
parent 801192a683
commit 2d68784a91
3 changed files with 33 additions and 0 deletions

View File

@ -97,6 +97,8 @@ private:
MonitorAutoLock& operator=(const MonitorAutoLock&);
static void* operator new(size_t) CPP_THROW_NEW;
friend class MonitorAutoUnlock;
Monitor* mMonitor;
};
@ -116,6 +118,12 @@ public:
mMonitor->Unlock();
}
explicit MonitorAutoUnlock(MonitorAutoLock& aMonitorLock)
: mMonitor(aMonitorLock.mMonitor)
{
mMonitor->Unlock();
}
~MonitorAutoUnlock()
{
mMonitor->Lock();

View File

@ -136,6 +136,9 @@ private:
Mutex& operator=(const Mutex&);
};
template<typename T>
class MOZ_RAII BaseAutoUnlock;
/**
* MutexAutoLock
* Acquires the Mutex when it enters scope, and releases it when it leaves
@ -174,6 +177,8 @@ private:
BaseAutoLock& operator=(BaseAutoLock&);
static void* operator new(size_t) CPP_THROW_NEW;
friend class BaseAutoUnlock<T>;
T* mLock;
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
};
@ -200,6 +205,15 @@ public:
mLock->Unlock();
}
explicit BaseAutoUnlock(
BaseAutoLock<T>& aAutoLock MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: mLock(aAutoLock.mLock)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
NS_ASSERTION(mLock, "null lock");
mLock->Unlock();
}
~BaseAutoUnlock()
{
mLock->Lock();

View File

@ -199,6 +199,8 @@ private:
ReentrantMonitorAutoEnter& operator=(const ReentrantMonitorAutoEnter&);
static void* operator new(size_t) CPP_THROW_NEW;
friend class ReentrantMonitorAutoExit;
mozilla::ReentrantMonitor* mReentrantMonitor;
};
@ -229,6 +231,15 @@ public:
mReentrantMonitor->Exit();
}
explicit ReentrantMonitorAutoExit(
ReentrantMonitorAutoEnter& aReentrantMonitorAutoEnter)
: mReentrantMonitor(aReentrantMonitorAutoEnter.mReentrantMonitor)
{
NS_ASSERTION(mReentrantMonitor, "null monitor");
mReentrantMonitor->AssertCurrentThreadIn();
mReentrantMonitor->Exit();
}
~ReentrantMonitorAutoExit(void)
{
mReentrantMonitor->Enter();