mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Move ScopedLock to ripple_basics
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
#include "UniqueNodeList.h"
|
||||
#include "ConnectionPool.h"
|
||||
#include "FeatureTable.h"
|
||||
#include "ScopedLock.h"
|
||||
#include "LedgerAcquire.h"
|
||||
#include "TransactionMaster.h"
|
||||
#include "Wallet.h"
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "modules/ripple_main/misc/ripple_HashValue.h"
|
||||
|
||||
#include "ScopedLock.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "SerializedTypes.h"
|
||||
#include "Ledger.h"
|
||||
#include "NetworkOPs.h"
|
||||
#include "ScopedLock.h"
|
||||
|
||||
#define LEDGER_CURRENT -1
|
||||
#define LEDGER_CLOSED -2
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include "ScopedLock.h"
|
||||
#include "HashedObject.h"
|
||||
#include "InstanceCounter.h"
|
||||
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
#ifndef __SCOPEDLOCKHOLDER__
|
||||
#define __SCOPEDLOCKHOLDER__
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
||||
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
|
||||
|
||||
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:
|
||||
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