mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-13 09:03:33 -04:00
fixed possible data race in mNotifications
This commit is contained in:
parent
3d7ae59df7
commit
93cd6a5df1
2 changed files with 19 additions and 3 deletions
|
@ -163,10 +163,25 @@ void RsGenExchange::tick()
|
||||||
|
|
||||||
processRoutingClues() ;
|
processRoutingClues() ;
|
||||||
|
|
||||||
if(!mNotifications.empty())
|
|
||||||
{
|
{
|
||||||
notifyChanges(mNotifications);
|
std::vector<RsGxsNotify*> mNotifications_copy;
|
||||||
mNotifications.clear();
|
|
||||||
|
// make a non-deep copy of mNotifications so that it can be passed off-mutex to notifyChanged()
|
||||||
|
// that will delete it. The potential high cost of notifyChanges() makes it preferable to call off-mutex.
|
||||||
|
{
|
||||||
|
RS_STACK_MUTEX(mGenMtx);
|
||||||
|
if(!mNotifications.empty())
|
||||||
|
{
|
||||||
|
mNotifications_copy = mNotifications;
|
||||||
|
mNotifications.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calling notifyChanges() calls back RsGxsIfaceHelper::receiveChanges() that deletes the pointers in the array
|
||||||
|
// and the array itself. This is pretty bad and we should normally delete the changes here.
|
||||||
|
|
||||||
|
if(!mNotifications_copy.empty())
|
||||||
|
notifyChanges(mNotifications_copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// implemented service tick function
|
// implemented service tick function
|
||||||
|
|
|
@ -377,6 +377,7 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
|
||||||
if(!unprocessedGroups.empty())
|
if(!unprocessedGroups.empty())
|
||||||
request_SpecificSubscribedGroups(unprocessedGroups);
|
request_SpecificSubscribedGroups(unprocessedGroups);
|
||||||
|
|
||||||
|
// the call below deletes changes and its content.
|
||||||
RsGxsIfaceHelper::receiveChanges(changes);
|
RsGxsIfaceHelper::receiveChanges(changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue