mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Some optimizations.
This commit is contained in:
@@ -133,6 +133,7 @@ public:
|
||||
bool isClosed() { return mClosed; }
|
||||
bool isAccepted() { return mAccepted; }
|
||||
bool isImmutable() { return mImmutable; }
|
||||
bool isFixed() { return mClosed || mImmutable; }
|
||||
|
||||
// ledger signature operations
|
||||
void addRaw(Serializer &s) const;
|
||||
|
||||
@@ -899,6 +899,8 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
ScopedUnlock su(theApp->getMasterLock(), lpLedger->isFixed());
|
||||
|
||||
if (!jvRequest.isMember("account"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
@@ -926,6 +928,7 @@ Json::Value RPCHandler::doAccountLines(Json::Value jvRequest)
|
||||
|
||||
jvResult["account"] = raAccount.humanAccountID();
|
||||
|
||||
|
||||
// XXX This is wrong, we do access the current ledger and do need to worry about changes.
|
||||
// We access a committed ledger and need not worry about changes.
|
||||
|
||||
@@ -977,6 +980,8 @@ Json::Value RPCHandler::doAccountOffers(Json::Value jvRequest)
|
||||
if (!lpLedger)
|
||||
return jvResult;
|
||||
|
||||
ScopedUnlock su(theApp->getMasterLock(), lpLedger->isClosed() || lpLedger->isImmutable());
|
||||
|
||||
if (!jvRequest.isMember("account"))
|
||||
return rpcError(rpcINVALID_PARAMS);
|
||||
|
||||
|
||||
@@ -29,11 +29,39 @@ public:
|
||||
class ScopedUnlock
|
||||
{
|
||||
protected:
|
||||
bool mUnlocked;
|
||||
boost::recursive_mutex& mMutex;
|
||||
|
||||
public:
|
||||
ScopedUnlock(boost::recursive_mutex& mutex) : mMutex(mutex) { mMutex.unlock(); }
|
||||
~ScopedUnlock() { mMutex.lock(); }
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user