mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-01 16:35:53 +00:00
Move ScopedLock to ripple_basics
This commit is contained in:
@@ -84,6 +84,12 @@ namespace boost {
|
||||
// RippleTime
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
// ScopedLock
|
||||
//#include <boost/thread/recursive_mutex.hpp>
|
||||
//#include <boost/shared_ptr.hpp>
|
||||
//#include <boost/make_shared.hpp>
|
||||
//#include <boost/ref.hpp>
|
||||
|
||||
// ByteOrder
|
||||
#ifdef WIN32
|
||||
// (nothing)
|
||||
@@ -122,6 +128,7 @@ namespace boost {
|
||||
#include "utility/ripple_DiffieHellmanUtil.h"
|
||||
#include "utility/ripple_PlatformMacros.h"
|
||||
#include "utility/ripple_RandomNumbers.h"
|
||||
#include "utility/ripple_ScopedLock.h"
|
||||
#include "utility/ripple_StringUtilities.h"
|
||||
#include "utility/ripple_Sustain.h"
|
||||
#include "utility/ripple_ThreadName.h"
|
||||
|
||||
69
modules/ripple_basics/utility/ripple_ScopedLock.h
Normal file
69
modules/ripple_basics/utility/ripple_ScopedLock.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef RIPPLE_SCOPEDLOCK_H
|
||||
#define RIPPLE_SCOPEDLOCK_H
|
||||
|
||||
typedef boost::recursive_mutex::scoped_lock ScopedLock;
|
||||
|
||||
// A lock holder that can be returned and copied by value
|
||||
// When the last reference goes away, the lock is released
|
||||
|
||||
// VFALCO: TODO, replace these with a more generic template, and not use boost
|
||||
//
|
||||
class SharedScopedLock
|
||||
{
|
||||
protected:
|
||||
mutable boost::shared_ptr<boost::recursive_mutex::scoped_lock> mHolder;
|
||||
|
||||
public:
|
||||
SharedScopedLock(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(); }
|
||||
};
|
||||
|
||||
// A class that unlocks on construction and locks on destruction
|
||||
|
||||
class ScopedUnlock
|
||||
{
|
||||
protected:
|
||||
bool mUnlocked;
|
||||
boost::recursive_mutex& mMutex;
|
||||
|
||||
public:
|
||||
// VFALCO: TODO, get rid of this unlock parameter to restore sanity
|
||||
ScopedUnlock(boost::recursive_mutex& mutex, bool unlock = true) : mUnlocked(unlock), mMutex(mutex)
|
||||
{
|
||||
if (unlock)
|
||||
mMutex.unlock();
|
||||
}
|
||||
|
||||
~ScopedUnlock()
|
||||
{
|
||||
if (mUnlocked)
|
||||
mMutex.lock();
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
if (mUnlocked)
|
||||
{
|
||||
mMutex.lock();
|
||||
mUnlocked = false;
|
||||
}
|
||||
}
|
||||
|
||||
void unlock()
|
||||
{
|
||||
if (!mUnlocked)
|
||||
{
|
||||
mUnlocked = true;
|
||||
mMutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
ScopedUnlock(const ScopedUnlock&); // no implementation
|
||||
ScopedUnlock& operator=(const ScopedUnlock&); // no implementation
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user