Add a scoped unlock class.

This commit is contained in:
JoelKatz
2012-11-09 14:13:03 -08:00
parent 546c0f288f
commit 82d26ea756

View File

@@ -16,16 +16,26 @@ protected:
public:
ScopedLock(boost::recursive_mutex& mutex) :
mHolder(boost::make_shared<boost::recursive_mutex::scoped_lock>(boost::ref(mutex)))
{ ; }
void lock() const
{
mHolder->lock();
}
void unlock() const
{
mHolder->unlock();
}
mHolder(boost::make_shared<boost::recursive_mutex::scoped_lock>(boost::ref(mutex))) { ; }
void lock() const { mHolder->lock(); }
void unlock() const { mHolder->unlock(); }
};
// A class that unlocks on construction and locks on destruction
class ScopedUnlock
{
protected:
boost::recursive_mutex& mMutex;
public:
ScopedUnlock(boost::recursive_mutex& mutex) : mMutex(mutex) { mMutex.unlock(); }
~ScopedUnlock() { mMutex.lock(); }
private:
ScopedUnlock(const ScopedUnlock&); // no implementation
ScopedUnlock& operator=(const ScopedUnlock&); // no implementation
};
#endif