added a temporary copy of mRequests in RsGxsDataAccess::processRequests() to avoid interactions with storeRequest() mofying the queue

This commit is contained in:
csoler 2020-04-05 16:41:44 +02:00
parent 25467dda9f
commit 9a1d589134
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C

View file

@ -771,30 +771,33 @@ void RsGxsDataAccess::processRequests()
clearRequest(*cit); clearRequest(*cit);
} }
// We hve to make a copy of the mRequest list because it can be modified while we treat the requests.
// This may happen because the mutex cannot be added around the full loop since it takes too much time.
std::map<uint32_t,GxsRequest*> request_list_copy;
{
RS_STACK_MUTEX(mDataMutex);
request_list_copy = mRequests;
}
// process requests // process requests
while (true) while (true)
{ {
GxsRequest* req = NULL; GxsRequest* req = NULL;
{ {
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
// get the first pending request // get the first pending request
for (it = mRequests.begin(); it != mRequests.end(); ++it) for (auto it:request_list_copy)
{ if (it.second->status == PENDING)
GxsRequest* reqCheck = it->second;
if (reqCheck->status == PENDING)
{ {
req = reqCheck; req = it.second;
req->status = PARTIAL; req->status = PARTIAL;
break; break;
} }
}
} // END OF MUTEX.
if (!req) {
break;
} }
if (!req)
break;
GroupMetaReq* gmr; GroupMetaReq* gmr;
GroupDataReq* gdr; GroupDataReq* gdr;
GroupIdReq* gir; GroupIdReq* gir;