mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Mutex debugging: added a new macro RS_STACK_MUTEX(myMutex) to trigger a scope guard while recording file location and line number. Moved the timings from RsMutex to RsStackMutex. Changed the mutexes in rsgenexchange and rsgxsntservice to use the new macro.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7672 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b25f6f30ef
commit
db4b87cd01
@ -221,7 +221,7 @@ void RsGenExchange::tick()
|
|||||||
|
|
||||||
if (!grpIds.empty())
|
if (!grpIds.empty())
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PROCESSED, false);
|
RsGxsGroupChange* gc = new RsGxsGroupChange(RsGxsNotify::TYPE_PROCESSED, false);
|
||||||
gc->mGrpIdList = grpIds;
|
gc->mGrpIdList = grpIds;
|
||||||
@ -229,7 +229,7 @@ void RsGenExchange::tick()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!msgIds.empty()) {
|
if (!msgIds.empty()) {
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, false);
|
RsGxsMsgChange* c = new RsGxsMsgChange(RsGxsNotify::TYPE_PROCESSED, false);
|
||||||
c->msgChangeMap = msgIds;
|
c->msgChangeMap = msgIds;
|
||||||
@ -262,7 +262,7 @@ bool RsGenExchange::messagePublicationTest(const RsGxsMsgMetaData& meta)
|
|||||||
bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,
|
bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,
|
||||||
RsGxsGrpMsgIdPair& msgId)
|
RsGxsGrpMsgIdPair& msgId)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "RsGenExchange::acknowledgeTokenMsg(). token=" << token << std::endl;
|
std::cerr << "RsGenExchange::acknowledgeTokenMsg(). token=" << token << std::endl;
|
||||||
@ -294,7 +294,7 @@ bool RsGenExchange::acknowledgeTokenMsg(const uint32_t& token,
|
|||||||
|
|
||||||
bool RsGenExchange::acknowledgeTokenGrp(const uint32_t& token, RsGxsGroupId& grpId)
|
bool RsGenExchange::acknowledgeTokenGrp(const uint32_t& token, RsGxsGroupId& grpId)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "RsGenExchange::acknowledgeTokenGrp(). token=" << token << std::endl;
|
std::cerr << "RsGenExchange::acknowledgeTokenGrp(). token=" << token << std::endl;
|
||||||
@ -984,7 +984,7 @@ bool RsGenExchange::checkAuthenFlag(const PrivacyBitPos& pos, const uint8_t& fla
|
|||||||
|
|
||||||
void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
|
void RsGenExchange::receiveChanges(std::vector<RsGxsNotify*>& changes)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
std::cerr << "RsGenExchange::receiveChanges()" << std::endl;
|
std::cerr << "RsGenExchange::receiveChanges()" << std::endl;
|
||||||
@ -1277,7 +1277,7 @@ bool RsGenExchange::getGroupData(const uint32_t &token, std::vector<RsGxsGrpItem
|
|||||||
|
|
||||||
bool RsGenExchange::getMsgData(const uint32_t &token, GxsMsgDataMap &msgItems)
|
bool RsGenExchange::getMsgData(const uint32_t &token, GxsMsgDataMap &msgItems)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
NxsMsgDataResult msgResult;
|
NxsMsgDataResult msgResult;
|
||||||
bool ok = mDataAccess->getMsgData(token, msgResult);
|
bool ok = mDataAccess->getMsgData(token, msgResult);
|
||||||
NxsMsgDataResult::iterator mit = msgResult.begin();
|
NxsMsgDataResult::iterator mit = msgResult.begin();
|
||||||
@ -1328,7 +1328,7 @@ bool RsGenExchange::getMsgData(const uint32_t &token, GxsMsgDataMap &msgItems)
|
|||||||
|
|
||||||
bool RsGenExchange::getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMap &msgItems)
|
bool RsGenExchange::getMsgRelatedData(const uint32_t &token, GxsMsgRelatedDataMap &msgItems)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
NxsMsgRelatedDataResult msgResult;
|
NxsMsgRelatedDataResult msgResult;
|
||||||
bool ok = mDataAccess->getMsgRelatedData(token, msgResult);
|
bool ok = mDataAccess->getMsgRelatedData(token, msgResult);
|
||||||
|
|
||||||
@ -1422,7 +1422,7 @@ bool RsGenExchange::setAuthenPolicyFlag(const uint8_t &msgFlag, uint32_t& authen
|
|||||||
|
|
||||||
void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
std::vector<RsNxsGrp*>::iterator vit = groups.begin();
|
std::vector<RsNxsGrp*>::iterator vit = groups.begin();
|
||||||
|
|
||||||
@ -1456,7 +1456,7 @@ void RsGenExchange::notifyNewGroups(std::vector<RsNxsGrp *> &groups)
|
|||||||
|
|
||||||
void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *>& messages)
|
void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *>& messages)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
|
std::vector<RsNxsMsg*>::iterator vit = messages.begin();
|
||||||
|
|
||||||
@ -1492,7 +1492,7 @@ void RsGenExchange::notifyNewMessages(std::vector<RsNxsMsg *>& messages)
|
|||||||
void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
|
void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
|
||||||
{
|
{
|
||||||
|
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
GxsGrpPendingSign ggps(grpItem, token);
|
GxsGrpPendingSign ggps(grpItem, token);
|
||||||
mGrpsToPublish.push_back(ggps);
|
mGrpsToPublish.push_back(ggps);
|
||||||
@ -1507,7 +1507,7 @@ void RsGenExchange::publishGroup(uint32_t& token, RsGxsGrpItem *grpItem)
|
|||||||
|
|
||||||
void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token));
|
mGroupUpdatePublish.push_back(GroupUpdatePublish(grpItem, token));
|
||||||
|
|
||||||
@ -1519,7 +1519,7 @@ void RsGenExchange::updateGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
|||||||
|
|
||||||
void RsGenExchange::deleteGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
void RsGenExchange::deleteGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
mGroupDeletePublish.push_back(GroupDeletePublish(grpItem, token));
|
mGroupDeletePublish.push_back(GroupDeletePublish(grpItem, token));
|
||||||
|
|
||||||
@ -1531,7 +1531,7 @@ void RsGenExchange::deleteGroup(uint32_t& token, RsGxsGrpItem* grpItem)
|
|||||||
|
|
||||||
void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
|
void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
mMsgsToPublish.insert(std::make_pair(token, msgItem));
|
mMsgsToPublish.insert(std::make_pair(token, msgItem));
|
||||||
|
|
||||||
@ -1545,7 +1545,7 @@ void RsGenExchange::publishMsg(uint32_t& token, RsGxsMsgItem *msgItem)
|
|||||||
void RsGenExchange::setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& flag, const uint32_t& mask)
|
void RsGenExchange::setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& flag, const uint32_t& mask)
|
||||||
{
|
{
|
||||||
/* TODO APPLY MASK TO FLAGS */
|
/* TODO APPLY MASK TO FLAGS */
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
|
|
||||||
GrpLocMetaData g;
|
GrpLocMetaData g;
|
||||||
@ -1558,7 +1558,7 @@ void RsGenExchange::setGroupSubscribeFlags(uint32_t& token, const RsGxsGroupId&
|
|||||||
void RsGenExchange::setGroupStatusFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask)
|
void RsGenExchange::setGroupStatusFlags(uint32_t& token, const RsGxsGroupId& grpId, const uint32_t& status, const uint32_t& mask)
|
||||||
{
|
{
|
||||||
/* TODO APPLY MASK TO FLAGS */
|
/* TODO APPLY MASK TO FLAGS */
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
|
|
||||||
GrpLocMetaData g;
|
GrpLocMetaData g;
|
||||||
@ -1571,7 +1571,7 @@ void RsGenExchange::setGroupStatusFlags(uint32_t& token, const RsGxsGroupId& grp
|
|||||||
|
|
||||||
void RsGenExchange::setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString)
|
void RsGenExchange::setGroupServiceString(uint32_t& token, const RsGxsGroupId& grpId, const std::string& servString)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
|
|
||||||
GrpLocMetaData g;
|
GrpLocMetaData g;
|
||||||
@ -1583,7 +1583,7 @@ void RsGenExchange::setGroupServiceString(uint32_t& token, const RsGxsGroupId& g
|
|||||||
void RsGenExchange::setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask)
|
void RsGenExchange::setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const uint32_t& status, const uint32_t& mask)
|
||||||
{
|
{
|
||||||
/* TODO APPLY MASK TO FLAGS */
|
/* TODO APPLY MASK TO FLAGS */
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
|
|
||||||
MsgLocMetaData m;
|
MsgLocMetaData m;
|
||||||
@ -1595,7 +1595,7 @@ void RsGenExchange::setMsgStatusFlags(uint32_t& token, const RsGxsGrpMsgIdPair&
|
|||||||
|
|
||||||
void RsGenExchange::setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString )
|
void RsGenExchange::setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, const std::string& servString )
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
|
|
||||||
MsgLocMetaData m;
|
MsgLocMetaData m;
|
||||||
@ -1606,7 +1606,7 @@ void RsGenExchange::setMsgServiceString(uint32_t& token, const RsGxsGrpMsgIdPair
|
|||||||
|
|
||||||
void RsGenExchange::processMsgMetaChanges()
|
void RsGenExchange::processMsgMetaChanges()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
GxsMsgReq msgIds;
|
GxsMsgReq msgIds;
|
||||||
|
|
||||||
@ -1682,7 +1682,7 @@ void RsGenExchange::processMsgMetaChanges()
|
|||||||
|
|
||||||
void RsGenExchange::processGrpMetaChanges()
|
void RsGenExchange::processGrpMetaChanges()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
std::list<RsGxsGroupId> grpChanged;
|
std::list<RsGxsGroupId> grpChanged;
|
||||||
|
|
||||||
@ -1775,7 +1775,7 @@ bool RsGenExchange::processGrpMask(const RsGxsGroupId& grpId, ContentValue &grpC
|
|||||||
void RsGenExchange::publishMsgs()
|
void RsGenExchange::publishMsgs()
|
||||||
{
|
{
|
||||||
|
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
// stick back msgs pending signature
|
// stick back msgs pending signature
|
||||||
typedef std::map<uint32_t, GxsPendingItem<RsGxsMsgItem*, uint32_t> > PendSignMap;
|
typedef std::map<uint32_t, GxsPendingItem<RsGxsMsgItem*, uint32_t> > PendSignMap;
|
||||||
@ -1970,7 +1970,7 @@ RsGenExchange::ServiceCreate_Return RsGenExchange::service_CreateGroup(RsGxsGrpI
|
|||||||
|
|
||||||
void RsGenExchange::processGroupUpdatePublish()
|
void RsGenExchange::processGroupUpdatePublish()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
// get keys for group update publish
|
// get keys for group update publish
|
||||||
|
|
||||||
@ -2040,7 +2040,7 @@ void RsGenExchange::processGroupUpdatePublish()
|
|||||||
|
|
||||||
void RsGenExchange::processRoutingClues()
|
void RsGenExchange::processRoutingClues()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
for(std::map<RsGxsId,std::set<RsPeerId> >::const_iterator it = mRoutingClues.begin();it!=mRoutingClues.end();++it)
|
for(std::map<RsGxsId,std::set<RsPeerId> >::const_iterator it = mRoutingClues.begin();it!=mRoutingClues.end();++it)
|
||||||
for(std::set<RsPeerId>::const_iterator it2(it->second.begin());it2!=it->second.end();++it2)
|
for(std::set<RsPeerId>::const_iterator it2(it->second.begin());it2!=it->second.end();++it2)
|
||||||
@ -2050,7 +2050,7 @@ void RsGenExchange::processRoutingClues()
|
|||||||
}
|
}
|
||||||
void RsGenExchange::processGroupDelete()
|
void RsGenExchange::processGroupDelete()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
// get keys for group delete publish
|
// get keys for group delete publish
|
||||||
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
||||||
@ -2122,7 +2122,7 @@ bool RsGenExchange::checkKeys(const RsTlvSecurityKeySet& keySet)
|
|||||||
|
|
||||||
void RsGenExchange::publishGrps()
|
void RsGenExchange::publishGrps()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
NxsGrpSignPendVect::iterator vit = mGrpsToPublish.begin();
|
NxsGrpSignPendVect::iterator vit = mGrpsToPublish.begin();
|
||||||
|
|
||||||
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
typedef std::pair<bool, RsGxsGroupId> GrpNote;
|
||||||
@ -2360,7 +2360,7 @@ bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet
|
|||||||
if(grpId.isNull())
|
if(grpId.isNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
|
||||||
grpMeta[grpId] = NULL;
|
grpMeta[grpId] = NULL;
|
||||||
@ -2410,7 +2410,7 @@ void RsGenExchange::computeHash(const RsTlvBinaryData& data, RsFileHash& hash)
|
|||||||
|
|
||||||
void RsGenExchange::processRecvdMessages()
|
void RsGenExchange::processRecvdMessages()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
#ifdef GEN_EXCH_DEBUG
|
#ifdef GEN_EXCH_DEBUG
|
||||||
if(!mMsgPendingValidate.empty())
|
if(!mMsgPendingValidate.empty())
|
||||||
@ -2604,7 +2604,7 @@ void RsGenExchange::processRecvdMessages()
|
|||||||
|
|
||||||
void RsGenExchange::processRecvdGroups()
|
void RsGenExchange::processRecvdGroups()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
if(mReceivedGrps.empty())
|
if(mReceivedGrps.empty())
|
||||||
return;
|
return;
|
||||||
@ -2721,7 +2721,7 @@ void RsGenExchange::processRecvdGroups()
|
|||||||
|
|
||||||
void RsGenExchange::performUpdateValidation()
|
void RsGenExchange::performUpdateValidation()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
|
|
||||||
if(mGroupUpdates.empty())
|
if(mGroupUpdates.empty())
|
||||||
return;
|
return;
|
||||||
@ -2816,7 +2816,7 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp)
|
|||||||
|
|
||||||
void RsGenExchange::setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff)
|
void RsGenExchange::setGroupReputationCutOff(uint32_t& token, const RsGxsGroupId& grpId, int CutOff)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mGenMtx);
|
RS_STACK_MUTEX(mGenMtx) ;
|
||||||
token = mDataAccess->generatePublicToken();
|
token = mDataAccess->generatePublicToken();
|
||||||
|
|
||||||
GrpLocMetaData g;
|
GrpLocMetaData g;
|
||||||
|
@ -106,7 +106,7 @@ public:
|
|||||||
|
|
||||||
static void recordEvent(uint16_t service_type, RsItem *item)
|
static void recordEvent(uint16_t service_type, RsItem *item)
|
||||||
{
|
{
|
||||||
RsStackMutex m(mtx) ;
|
RS_STACK_MUTEX(mtx) ;
|
||||||
|
|
||||||
uint32_t bw = RsNxsSerialiser(service_type).size(item) ; // this is used to estimate bandwidth.
|
uint32_t bw = RsNxsSerialiser(service_type).size(item) ; // this is used to estimate bandwidth.
|
||||||
timeval tv ;
|
timeval tv ;
|
||||||
@ -208,7 +208,7 @@ void RsGxsNetService::syncWithPeers()
|
|||||||
|
|
||||||
static RsNxsSerialiser ser(mServType) ; // this is used to estimate bandwidth.
|
static RsNxsSerialiser ser(mServType) ; // this is used to estimate bandwidth.
|
||||||
|
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
std::set<RsPeerId> peers;
|
std::set<RsPeerId> peers;
|
||||||
mNetMgr->getOnlineList(mServiceInfo.mServiceType, peers);
|
mNetMgr->getOnlineList(mServiceInfo.mServiceType, peers);
|
||||||
@ -811,7 +811,7 @@ struct get_second : public std::unary_function<typename UpdateMap::value_type, R
|
|||||||
|
|
||||||
bool RsGxsNetService::saveList(bool& cleanup, std::list<RsItem*>& save)
|
bool RsGxsNetService::saveList(bool& cleanup, std::list<RsItem*>& save)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
// hardcore templates
|
// hardcore templates
|
||||||
std::transform(mClientGrpUpdateMap.begin(), mClientGrpUpdateMap.end(),
|
std::transform(mClientGrpUpdateMap.begin(), mClientGrpUpdateMap.end(),
|
||||||
@ -896,7 +896,7 @@ bool RsGxsNetService::handleTransaction(RsNxsItem* item)
|
|||||||
* If it does then check this not a initiating transactions
|
* If it does then check this not a initiating transactions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
const RsPeerId& peer = item->PeerId();
|
const RsPeerId& peer = item->PeerId();
|
||||||
|
|
||||||
@ -1081,7 +1081,7 @@ void RsGxsNetService::run(){
|
|||||||
|
|
||||||
void RsGxsNetService::updateServerSyncTS()
|
void RsGxsNetService::updateServerSyncTS()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
std::map<RsGxsGroupId, RsGxsGrpMetaData*> gxsMap;
|
std::map<RsGxsGroupId, RsGxsGrpMetaData*> gxsMap;
|
||||||
|
|
||||||
@ -1143,7 +1143,7 @@ bool RsGxsNetService::locked_checkTransacTimedOut(NxsTransaction* tr)
|
|||||||
|
|
||||||
void RsGxsNetService::processTransactions(){
|
void RsGxsNetService::processTransactions(){
|
||||||
|
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
TransactionsPeerMap::iterator mit = mTransactions.begin();
|
TransactionsPeerMap::iterator mit = mTransactions.begin();
|
||||||
|
|
||||||
@ -1330,7 +1330,7 @@ void RsGxsNetService::processTransactions(){
|
|||||||
|
|
||||||
int RsGxsNetService::getGroupPopularity(const RsGxsGroupId& gid)
|
int RsGxsNetService::getGroupPopularity(const RsGxsGroupId& gid)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
std::map<RsGxsGroupId,std::set<RsPeerId> >::const_iterator it = mGroupSuppliers.find(gid) ;
|
std::map<RsGxsGroupId,std::set<RsPeerId> >::const_iterator it = mGroupSuppliers.find(gid) ;
|
||||||
|
|
||||||
@ -1342,7 +1342,7 @@ int RsGxsNetService::getGroupPopularity(const RsGxsGroupId& gid)
|
|||||||
|
|
||||||
void RsGxsNetService::processCompletedTransactions()
|
void RsGxsNetService::processCompletedTransactions()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
/*!
|
/*!
|
||||||
* Depending on transaction we may have to respond to peer
|
* Depending on transaction we may have to respond to peer
|
||||||
* responsible for transaction
|
* responsible for transaction
|
||||||
@ -2006,7 +2006,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
|
|||||||
|
|
||||||
void RsGxsNetService::runVetting()
|
void RsGxsNetService::runVetting()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
std::vector<AuthorPending*>::iterator vit = mPendingResp.begin();
|
std::vector<AuthorPending*>::iterator vit = mPendingResp.begin();
|
||||||
|
|
||||||
@ -2281,7 +2281,7 @@ bool RsGxsNetService::locked_CanReceiveUpdate(const RsNxsSyncGrp *item)
|
|||||||
void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
void RsGxsNetService::handleRecvSyncGroup(RsNxsSyncGrp* item)
|
||||||
{
|
{
|
||||||
|
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
if(!locked_CanReceiveUpdate(item))
|
if(!locked_CanReceiveUpdate(item))
|
||||||
{
|
{
|
||||||
@ -2629,7 +2629,7 @@ bool RsGxsNetService::locked_CanReceiveUpdate(const RsNxsSyncMsg *item)
|
|||||||
}
|
}
|
||||||
void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
void RsGxsNetService::handleRecvSyncMessage(RsNxsSyncMsg* item)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
// We do that early, so as to get info about who sends data about which group,
|
// We do that early, so as to get info about who sends data about which group,
|
||||||
// even when the group doesn't need update.
|
// even when the group doesn't need update.
|
||||||
@ -2827,14 +2827,14 @@ void RsGxsNetService::setSyncAge(uint32_t /* age */)
|
|||||||
|
|
||||||
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)
|
int RsGxsNetService::requestGrp(const std::list<RsGxsGroupId>& grpId, const RsPeerId& peerId)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
mExplicitRequest[peerId].assign(grpId.begin(), grpId.end());
|
mExplicitRequest[peerId].assign(grpId.begin(), grpId.end());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsGxsNetService::processExplicitGroupRequests()
|
void RsGxsNetService::processExplicitGroupRequests()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
std::map<RsPeerId, std::list<RsGxsGroupId> >::const_iterator cit = mExplicitRequest.begin();
|
std::map<RsPeerId, std::list<RsGxsGroupId> >::const_iterator cit = mExplicitRequest.begin();
|
||||||
|
|
||||||
@ -2866,7 +2866,7 @@ void RsGxsNetService::processExplicitGroupRequests()
|
|||||||
#define NXS_NET_DEBUG
|
#define NXS_NET_DEBUG
|
||||||
int RsGxsNetService::sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers)
|
int RsGxsNetService::sharePublishKey(const RsGxsGroupId& grpId,const std::list<RsPeerId>& peers)
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
mPendingPublishKeyRecipients[grpId] = peers ;
|
mPendingPublishKeyRecipients[grpId] = peers ;
|
||||||
|
|
||||||
@ -2877,7 +2877,7 @@ int RsGxsNetService::sharePublishKey(const RsGxsGroupId& grpId,const std::list<R
|
|||||||
|
|
||||||
void RsGxsNetService::sharePublishKeysPending()
|
void RsGxsNetService::sharePublishKeysPending()
|
||||||
{
|
{
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
if(mPendingPublishKeyRecipients.empty())
|
if(mPendingPublishKeyRecipients.empty())
|
||||||
return ;
|
return ;
|
||||||
@ -3001,7 +3001,7 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
|
|||||||
#ifdef NXS_NET_DEBUG
|
#ifdef NXS_NET_DEBUG
|
||||||
std::cerr << "RsGxsNetService::sharePublishKeys() " << std::endl;
|
std::cerr << "RsGxsNetService::sharePublishKeys() " << std::endl;
|
||||||
#endif
|
#endif
|
||||||
RsStackMutex stack(mNxsMutex);
|
RS_STACK_MUTEX(mNxsMutex) ;
|
||||||
|
|
||||||
#ifdef NXS_NET_DEBUG
|
#ifdef NXS_NET_DEBUG
|
||||||
std::cerr << " PeerId : " << item->PeerId() << std::endl;
|
std::cerr << " PeerId : " << item->PeerId() << std::endl;
|
||||||
|
@ -185,12 +185,6 @@ void RsMutex::unlock()
|
|||||||
#endif
|
#endif
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
_thread_id = 0 ;
|
_thread_id = 0 ;
|
||||||
#endif
|
|
||||||
#ifdef RSMUTEX_DEBUG
|
|
||||||
double ts = getCurrentTS() ;
|
|
||||||
|
|
||||||
if(ts - _time_stamp > 1.0) // locked for more than 0.5 seconds => somthing fishy is happenning
|
|
||||||
std::cerr << "Mutex " << (void*)this << " \"" << name << "\"" << " got locked for " << ts - _time_stamp << " seconds in thread " << pthread_self() << std::endl;
|
|
||||||
#endif
|
#endif
|
||||||
pthread_mutex_unlock(&realMutex);
|
pthread_mutex_unlock(&realMutex);
|
||||||
|
|
||||||
@ -202,7 +196,6 @@ void RsMutex::unlock()
|
|||||||
void RsMutex::lock()
|
void RsMutex::lock()
|
||||||
{
|
{
|
||||||
#ifdef RSMUTEX_DEBUG
|
#ifdef RSMUTEX_DEBUG
|
||||||
_time_stamp = getCurrentTS() ;
|
|
||||||
pthread_t owner = _thread_id ;
|
pthread_t owner = _thread_id ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -213,14 +206,6 @@ void RsMutex::lock()
|
|||||||
#endif
|
#endif
|
||||||
retval = pthread_mutex_lock(&realMutex);
|
retval = pthread_mutex_lock(&realMutex);
|
||||||
|
|
||||||
#ifdef RSMUTEX_DEBUG
|
|
||||||
double ts = getCurrentTS() ;
|
|
||||||
|
|
||||||
if(ts - _time_stamp > 1.0)
|
|
||||||
std::cerr << "Mutex " << (void*)this << " \"" << name << "\"" << " waited for " << ts - _time_stamp << " seconds in thread " << pthread_self() << " for locked thread " << owner << std::endl;
|
|
||||||
|
|
||||||
_time_stamp = getCurrentTS() ; // This is to re-init the locking time without accounting for how much we waited.
|
|
||||||
#endif
|
|
||||||
switch(retval)
|
switch(retval)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -279,9 +264,8 @@ void RsMutex::lock()
|
|||||||
++_cnt ;
|
++_cnt ;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RSMUTEX_DEBUG
|
#ifdef RSMUTEX_DEBUG
|
||||||
double RsMutex::getCurrentTS()
|
double RsStackMutex::getCurrentTS()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifndef WINDOWS_SYS
|
#ifndef WINDOWS_SYS
|
||||||
@ -297,3 +281,4 @@ double RsMutex::getCurrentTS()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
/* RsIface Thread Wrappers */
|
/* RsIface Thread Wrappers */
|
||||||
|
|
||||||
@ -44,14 +45,15 @@ class RsMutex
|
|||||||
RsMutex(const std::string& name)
|
RsMutex(const std::string& name)
|
||||||
{
|
{
|
||||||
/* remove unused parameter warnings */
|
/* remove unused parameter warnings */
|
||||||
(void) name;
|
|
||||||
|
|
||||||
pthread_mutex_init(&realMutex, NULL);
|
pthread_mutex_init(&realMutex, NULL);
|
||||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||||
_thread_id = 0 ;
|
_thread_id = 0 ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef RSMUTEX_DEBUG
|
#ifdef RSMUTEX_DEBUG
|
||||||
this->name = name;
|
this->_name = name;
|
||||||
|
#else
|
||||||
|
(void) name;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
~RsMutex()
|
~RsMutex()
|
||||||
@ -63,7 +65,7 @@ class RsMutex
|
|||||||
#ifdef RSMUTEX_DEBUG
|
#ifdef RSMUTEX_DEBUG
|
||||||
void setName(const std::string &name)
|
void setName(const std::string &name)
|
||||||
{
|
{
|
||||||
this->name = name;
|
this->_name = name;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -71,6 +73,10 @@ class RsMutex
|
|||||||
void unlock();
|
void unlock();
|
||||||
bool trylock() { return (0 == pthread_mutex_trylock(&realMutex)); }
|
bool trylock() { return (0 == pthread_mutex_trylock(&realMutex)); }
|
||||||
|
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
const std::string& name() const { return _name ; }
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_mutex_t realMutex;
|
pthread_mutex_t realMutex;
|
||||||
pthread_t _thread_id ;
|
pthread_t _thread_id ;
|
||||||
@ -78,10 +84,7 @@ class RsMutex
|
|||||||
uint32_t _cnt ;
|
uint32_t _cnt ;
|
||||||
#endif
|
#endif
|
||||||
#ifdef RSMUTEX_DEBUG
|
#ifdef RSMUTEX_DEBUG
|
||||||
static double getCurrentTS() ;
|
std::string _name;
|
||||||
|
|
||||||
std::string name;
|
|
||||||
double _time_stamp ;
|
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -89,13 +92,80 @@ class RsStackMutex
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RsStackMutex(RsMutex &mtx): mMtx(mtx) { mMtx.lock(); }
|
RsStackMutex(RsMutex &mtx)
|
||||||
~RsStackMutex() { mMtx.unlock(); }
|
: mMtx(mtx)
|
||||||
|
{
|
||||||
|
mMtx.lock();
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
double ts = getCurrentTS() ;
|
||||||
|
_time_stamp = ts ;
|
||||||
|
_lineno = 0 ;
|
||||||
|
_info = "[no info]" ;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
RsStackMutex(RsMutex &mtx,const char *function_name,const char *file_name,int lineno)
|
||||||
|
: mMtx(mtx)
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
, _info(std::string(function_name)+" in file "+file_name),_lineno(lineno)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
double ts = getCurrentTS() ;
|
||||||
|
_time_stamp = ts ;
|
||||||
|
pthread_t owner = mMtx.owner() ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mMtx.lock();
|
||||||
|
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
ts = getCurrentTS() ;
|
||||||
|
|
||||||
|
if(ts - _time_stamp > 1.0)
|
||||||
|
std::cerr << "Mutex " << (void*)&mMtx << " \"" << mtx.name() << "\""
|
||||||
|
<< " waited for " << ts - _time_stamp
|
||||||
|
<< " seconds in thread " << pthread_self()
|
||||||
|
<< " for locked thread " << owner << ". in " << _info << ":" << _lineno << std::endl;
|
||||||
|
|
||||||
|
_time_stamp = ts ; // This is to re-init the locking time without accounting for how much we waited.
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
~RsStackMutex()
|
||||||
|
{
|
||||||
|
mMtx.unlock();
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
double ts = getCurrentTS() ;
|
||||||
|
|
||||||
|
if(ts - _time_stamp > 1.0)
|
||||||
|
std::cerr << "Mutex " << (void*)&mMtx << " \"" << mMtx.name() << "\""
|
||||||
|
<< " locked for " << ts - _time_stamp
|
||||||
|
<< " seconds in thread " << pthread_self()
|
||||||
|
<< ". in " << _info << ":" << _lineno << std::endl;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RsMutex &mMtx;
|
RsMutex &mMtx;
|
||||||
|
|
||||||
|
#ifdef RSMUTEX_DEBUG
|
||||||
|
static double getCurrentTS() ;
|
||||||
|
double _time_stamp ;
|
||||||
|
std::string _info ;
|
||||||
|
int _lineno ;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// This macro allows you to trace which mutex in the code is locked for how much time.
|
||||||
|
// se this as follows:
|
||||||
|
//
|
||||||
|
// {
|
||||||
|
// RS_STACK_MUTEX(myMutex) ;
|
||||||
|
//
|
||||||
|
// do_something() ;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
#define RS_STACK_MUTEX(m) RsStackMutex __local_retroshare_mutex(m,__PRETTY_FUNCTION__,__FILE__,__LINE__)
|
||||||
|
|
||||||
class RsThread;
|
class RsThread;
|
||||||
|
|
||||||
/* to create a thread! */
|
/* to create a thread! */
|
||||||
|
Loading…
Reference in New Issue
Block a user