Pathfinding dispatch improvements

* Keep requests forwards, flip only on insert
* Insert requests in more sensible order (after new, before old)
* Remove a redundant cache/request check
This commit is contained in:
JoelKatz
2014-02-04 13:15:24 -08:00
committed by Vinnie Falco
parent 41c0702408
commit f2beb82b97
3 changed files with 32 additions and 18 deletions

View File

@@ -74,6 +74,12 @@ bool PathRequest::isValid ()
return bValid;
}
bool PathRequest::isNew ()
{
// does this path request still need its first full path
return iLastIndex.load() == 0;
}
bool PathRequest::needsUpdate (bool newOnly, LedgerIndex index)
{
LedgerIndex lastIndex = iLastIndex.load();

View File

@@ -53,6 +53,7 @@ public:
bool isValid (const boost::shared_ptr<Ledger>&);
bool isValid ();
bool isNew ();
bool needsUpdate (bool newOnly, LedgerIndex index);
Json::Value getStatus ();

View File

@@ -67,23 +67,6 @@ void PathRequests::updateAll (Ledger::ref inLedger, CancelCallback shouldCancel)
do
{
{ // Get the latest requests, cache, and ledger
ScopedLockType sl (mLock, __FILE__, __LINE__);
if (mRequests.empty())
return;
// Newest request is last in mRequests, but we want to serve it first
requests.empty();
requests.reserve (mRequests.size ());
BOOST_REVERSE_FOREACH (PathRequest::wptr& req, mRequests)
{
requests.push_back (req);
}
cache = getLineCache (ledger, false);
}
BOOST_FOREACH (PathRequest::wref wRequest, requests)
{
if (shouldCancel())
@@ -152,6 +135,17 @@ void PathRequests::updateAll (Ledger::ref inLedger, CancelCallback shouldCancel)
return;
}
{
// Get the latest requests, cache, and ledger for next pass
ScopedLockType sl (mLock, __FILE__, __LINE__);
if (mRequests.empty())
break;
requests = mRequests;
cache = getLineCache (ledger, false);
}
}
while (!shouldCancel ());
@@ -182,7 +176,20 @@ Json::Value PathRequests::makePathRequest(
{
{
ScopedLockType sl (mLock, __FILE__, __LINE__);
mRequests.push_back (req);
// Insert after any older unserviced requests but before any serviced requests
std::vector<PathRequest::wptr>::iterator it = mRequests.begin ();
while (it != mRequests.end ())
{
PathRequest::pointer req = it->lock ();
if (req && !req->isNew ())
break; // This request has been handled, we come before it
// This is a newer request, we come after it
++it;
}
mRequests.insert (it, PathRequest::wptr (req));
}
subscriber->setPathRequest (req);
getApp().getLedgerMaster().newPathRequest();