Rewrite the notification code to use smart pointers. This fixes several

fatal race conditions in notifications. This makes failure to remove a
notification non-fatal (it will remove itself harmlessly when an attempt is
made to notify it).
This commit is contained in:
JoelKatz
2013-02-26 00:11:23 -08:00
parent 5fb29bb859
commit c570cca15e
8 changed files with 209 additions and 140 deletions

View File

@@ -232,23 +232,31 @@ void OrderBookDB::processTxn(const SerializedTransaction& stTxn, TER terResult,T
}
}
void BookListeners::addSubscriber(InfoSub* sub)
void BookListeners::addSubscriber(InfoSub::ref sub)
{
mListeners.insert(sub);
mListeners[sub->getSeq()] = sub;
}
void BookListeners::removeSubscriber(InfoSub* sub)
void BookListeners::removeSubscriber(uint64 seq)
{
mListeners.erase(sub);
mListeners.erase(seq);
}
void BookListeners::publish(Json::Value& jvObj)
{
//Json::Value jvObj=node.getJson(0);
BOOST_FOREACH(InfoSub* sub,mListeners)
NetworkOPs::subMapType::const_iterator it = mListeners.begin();
while (it != mListeners.end())
{
sub->send(jvObj, true);
InfoSub::pointer p = it->second.lock();
if (p)
{
p->send(jvObj, true);
++it;
}
else
it = mListeners.erase(it);
}
}