mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Add a scoped unlock class.
This commit is contained in:
@@ -16,16 +16,26 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ScopedLock(boost::recursive_mutex& mutex) :
|
ScopedLock(boost::recursive_mutex& mutex) :
|
||||||
mHolder(boost::make_shared<boost::recursive_mutex::scoped_lock>(boost::ref(mutex)))
|
mHolder(boost::make_shared<boost::recursive_mutex::scoped_lock>(boost::ref(mutex))) { ; }
|
||||||
{ ; }
|
|
||||||
void lock() const
|
void lock() const { mHolder->lock(); }
|
||||||
{
|
void unlock() const { mHolder->unlock(); }
|
||||||
mHolder->lock();
|
};
|
||||||
}
|
|
||||||
void unlock() const
|
// A class that unlocks on construction and locks on destruction
|
||||||
{
|
|
||||||
mHolder->unlock();
|
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
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user