added missing mutex in nxstesthub

This commit is contained in:
electron128 2015-12-13 20:50:08 +01:00
parent aa93505860
commit c03ce56591
2 changed files with 12 additions and 2 deletions

View File

@ -60,7 +60,7 @@ private:
}; };
rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario::pointer testScenario) rs_nxs_test::NxsTestHub::NxsTestHub(NxsTestScenario::pointer testScenario)
: mTestScenario(testScenario) : mTestScenario(testScenario), mMtx("NxsTestHub Mutex")
{ {
std::list<RsPeerId> peers; std::list<RsPeerId> peers;
mTestScenario->getPeers(peers); mTestScenario->getPeers(peers);
@ -151,6 +151,7 @@ void rs_nxs_test::NxsTestHub::EndTest()
void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid, void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid,
std::vector<RsNxsMsg*>& messages) std::vector<RsNxsMsg*>& messages)
{ {
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
std::map<RsNxsMsg*, RsGxsMsgMetaData*> toStore; std::map<RsNxsMsg*, RsGxsMsgMetaData*> toStore;
std::vector<RsNxsMsg*>::iterator it = messages.begin(); std::vector<RsNxsMsg*>::iterator it = messages.begin();
@ -169,6 +170,8 @@ void rs_nxs_test::NxsTestHub::notifyNewMessages(const RsPeerId& pid,
void rs_nxs_test::NxsTestHub::notifyNewGroups(const RsPeerId& pid, std::vector<RsNxsGrp*>& groups) void rs_nxs_test::NxsTestHub::notifyNewGroups(const RsPeerId& pid, std::vector<RsNxsGrp*>& groups)
{ {
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
std::map<RsNxsGrp*, RsGxsGrpMetaData*> toStore; std::map<RsNxsGrp*, RsGxsGrpMetaData*> toStore;
std::vector<RsNxsGrp*>::iterator it = groups.begin(); std::vector<RsNxsGrp*>::iterator it = groups.begin();
for(; it != groups.end(); it++) for(; it != groups.end(); it++)
@ -196,6 +199,7 @@ void rs_nxs_test::NxsTestHub::Wait(int seconds) {
bool rs_nxs_test::NxsTestHub::recvItem(RsRawItem* item, const RsPeerId& peerFrom) bool rs_nxs_test::NxsTestHub::recvItem(RsRawItem* item, const RsPeerId& peerFrom)
{ {
RS_STACK_MUTEX(mMtx); /***** MTX LOCKED *****/
PayLoad p(peerFrom, item); PayLoad p(peerFrom, item);
mPayLoad.push(p); mPayLoad.push(p);
return true; return true;
@ -213,6 +217,7 @@ void rs_nxs_test::NxsTestHub::tick()
PeerNxsMap::iterator it = mPeerNxsMap.begin(); PeerNxsMap::iterator it = mPeerNxsMap.begin();
// deliver payloads to peer's net services // deliver payloads to peer's net services
mMtx.lock();
while(!mPayLoad.empty()) while(!mPayLoad.empty())
{ {
PayLoad& p = mPayLoad.front(); PayLoad& p = mPayLoad.front();
@ -221,9 +226,12 @@ void rs_nxs_test::NxsTestHub::tick()
RsPeerId peerFrom = p.first; RsPeerId peerFrom = p.first;
RsPeerId peerTo = item->PeerId(); RsPeerId peerTo = item->PeerId();
item->PeerId(peerFrom); item->PeerId(peerFrom);
mPeerNxsMap[peerTo]->recv(item); // mMtx.unlock();
mPeerNxsMap[peerTo]->recv(item);
mMtx.lock();
mPayLoad.pop(); mPayLoad.pop();
} }
mMtx.unlock();
// then tick net services // then tick net services
for(; it != mPeerNxsMap.end(); it++) for(; it != mPeerNxsMap.end(); it++)

View File

@ -104,6 +104,8 @@ namespace rs_nxs_test
typedef std::pair<RsPeerId, RsRawItem*> PayLoad; typedef std::pair<RsPeerId, RsRawItem*> PayLoad;
typedef std::map<RsPeerId, RsGxsNetService::pointer > PeerNxsMap ; typedef std::map<RsPeerId, RsGxsNetService::pointer > PeerNxsMap ;
RsMutex mMtx;
PeerNxsMap mPeerNxsMap; PeerNxsMap mPeerNxsMap;
NxsTestScenario::pointer mTestScenario; NxsTestScenario::pointer mTestScenario;
std::queue<PayLoad> mPayLoad; std::queue<PayLoad> mPayLoad;