Some optimizations.

This commit is contained in:
JoelKatz
2013-02-20 09:33:09 -08:00
parent c375d2d96b
commit 7552f9eacf
3 changed files with 36 additions and 2 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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