fixed possible data race in mNotifications

This commit is contained in:
csoler 2019-12-19 21:03:08 +01:00
parent 3d7ae59df7
commit 93cd6a5df1
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
2 changed files with 19 additions and 3 deletions

View File

@ -163,10 +163,25 @@ void RsGenExchange::tick()
processRoutingClues() ;
if(!mNotifications.empty())
{
notifyChanges(mNotifications);
mNotifications.clear();
std::vector<RsGxsNotify*> mNotifications_copy;
// 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

View File

@ -377,6 +377,7 @@ void p3GxsChannels::notifyChanges(std::vector<RsGxsNotify *> &changes)
if(!unprocessedGroups.empty())
request_SpecificSubscribedGroups(unprocessedGroups);
// the call below deletes changes and its content.
RsGxsIfaceHelper::receiveChanges(changes);
}