mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added missing mutex in nxstesthub
This commit is contained in:
parent
aa93505860
commit
c03ce56591
@ -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++)
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user