Browse Source

fixed race condition

pull/97/head
orignal 10 years ago
parent
commit
cade0e6afa
  1. 3
      NetDb.cpp
  2. 1
      NetDb.h

3
NetDb.cpp

@ -751,6 +751,7 @@ namespace data
if (it == m_RequestedDestinations.end ()) // not exist yet if (it == m_RequestedDestinations.end ()) // not exist yet
{ {
RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory, pool); RequestedDestination * d = new RequestedDestination (dest, isLeaseSet, isExploratory, pool);
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
m_RequestedDestinations[dest] = d; m_RequestedDestinations[dest] = d;
return d; return d;
} }
@ -764,6 +765,7 @@ namespace data
if (it != m_RequestedDestinations.end ()) if (it != m_RequestedDestinations.end ())
{ {
delete it->second; delete it->second;
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
m_RequestedDestinations.erase (it); m_RequestedDestinations.erase (it);
return true; return true;
} }
@ -774,6 +776,7 @@ namespace data
{ {
if (dest) if (dest)
{ {
std::unique_lock<std::mutex> l(m_RequestedDestinationsMutex);
m_RequestedDestinations.erase (dest->GetDestination ()); m_RequestedDestinations.erase (dest->GetDestination ());
delete dest; delete dest;
} }

1
NetDb.h

@ -110,6 +110,7 @@ namespace data
std::map<IdentHash, LeaseSet *> m_LeaseSets; std::map<IdentHash, LeaseSet *> m_LeaseSets;
std::map<IdentHash, RouterInfo *> m_RouterInfos; std::map<IdentHash, RouterInfo *> m_RouterInfos;
std::vector<RouterInfo *> m_Floodfills; std::vector<RouterInfo *> m_Floodfills;
std::mutex m_RequestedDestinationsMutex;
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations; std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;
std::set<IdentHash> m_Subscriptions; std::set<IdentHash> m_Subscriptions;

Loading…
Cancel
Save