diff --git a/libretroshare/src/gxs/rsgenexchange.cc b/libretroshare/src/gxs/rsgenexchange.cc index 0d10eddf0..c3417d186 100644 --- a/libretroshare/src/gxs/rsgenexchange.cc +++ b/libretroshare/src/gxs/rsgenexchange.cc @@ -1634,14 +1634,22 @@ void RsGenExchange::setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair void RsGenExchange::processMsgMetaChanges() { - RS_STACK_MUTEX(mGenMtx) ; + std::map metaMap; + + { + RS_STACK_MUTEX(mGenMtx); + if (mMsgLocMetaMap.empty()) + { + return; + } + metaMap = mMsgLocMetaMap; + mMsgLocMetaMap.clear(); + } GxsMsgReq msgIds; - std::map::iterator mit = mMsgLocMetaMap.begin(), - mit_end = mMsgLocMetaMap.end(); - - for(; mit != mit_end; ++mit) + std::map::iterator mit; + for (mit = metaMap.begin(); mit != metaMap.end(); ++mit) { MsgLocMetaData& m = mit->second; @@ -1696,28 +1704,39 @@ void RsGenExchange::processMsgMetaChanges() { mDataAccess->updatePublicRequestStatus(token, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED); } - mMsgNotify.insert(std::make_pair(token, m.msgId)); + + { + RS_STACK_MUTEX(mGenMtx); + mMsgNotify.insert(std::make_pair(token, m.msgId)); + } } if (!msgIds.empty()) { + RS_STACK_MUTEX(mGenMtx); RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, true); c->msgChangeMap = msgIds; mNotifications.push_back(c); } - - mMsgLocMetaMap.clear(); } void RsGenExchange::processGrpMetaChanges() { - RS_STACK_MUTEX(mGenMtx) ; + std::map metaMap; + + { + RS_STACK_MUTEX(mGenMtx); + if (mGrpLocMetaMap.empty()) + { + return; + } + metaMap = mGrpLocMetaMap; + mGrpLocMetaMap.clear(); + } std::list grpChanged; - std::map::iterator mit = mGrpLocMetaMap.begin(), - mit_end = mGrpLocMetaMap.end(); - - for(; mit != mit_end; ++mit) + std::map::iterator mit; + for (mit = metaMap.begin(); mit != metaMap.end(); ++mit) { GrpLocMetaData& g = mit->second; uint32_t token = mit->first; @@ -1735,17 +1754,20 @@ void RsGenExchange::processGrpMetaChanges() { mDataAccess->updatePublicRequestStatus(token, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED); } - mGrpNotify.insert(std::make_pair(token, g.grpId)); + + { + RS_STACK_MUTEX(mGenMtx); + mGrpNotify.insert(std::make_pair(token, g.grpId)); + } } if(!grpChanged.empty()) { + RS_STACK_MUTEX(mGenMtx); RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PROCESSED, true); gc->mGrpIdList = grpChanged; mNotifications.push_back(gc); } - - mGrpLocMetaMap.clear(); } bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpCv)