From 02d228b94b2719792dce339b0ef7370bb67b408a Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 21 Nov 2010 15:08:33 +0000 Subject: [PATCH] added missing locks git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3841 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dht/p3bitdht.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/dht/p3bitdht.cc b/libretroshare/src/dht/p3bitdht.cc index a59497614..bd396e942 100644 --- a/libretroshare/src/dht/p3bitdht.cc +++ b/libretroshare/src/dht/p3bitdht.cc @@ -88,6 +88,7 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, UdpStack *udpstack, std::st bdStdPrintNodeId(std::cerr, &ownId); std::cerr << std::endl; + RsStackMutex stack(dhtMtx); /* standard dht behaviour */ bdDhtFunctions *stdfns = new bdStdDht(); @@ -108,6 +109,7 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, UdpStack *udpstack, std::st p3BitDht::~p3BitDht() { //udpstack->removeReceiver(mUdpBitDht); + RsStackMutex stack(dhtMtx); delete mUdpBitDht; } @@ -116,6 +118,7 @@ void p3BitDht::start() std::cerr << "p3BitDht::start()"; std::cerr << std::endl; + RsStackMutex stack(dhtMtx); mUdpBitDht->start(); /* starts up the bitdht thread */ /* dht switched on by config later. */ @@ -129,38 +132,45 @@ void p3BitDht::enable(bool on) if (on) { + RsStackMutex stack(dhtMtx); mUdpBitDht->startDht(); } else { + RsStackMutex stack(dhtMtx); mUdpBitDht->stopDht(); } } void p3BitDht::shutdown() /* blocking call */ { + RsStackMutex stack(dhtMtx); mUdpBitDht->stopDht(); } void p3BitDht::restart() { + RsStackMutex stack(dhtMtx); mUdpBitDht->stopDht(); mUdpBitDht->startDht(); } bool p3BitDht::getEnabled() { + RsStackMutex stack(dhtMtx); return (mUdpBitDht->stateDht() != 0); } bool p3BitDht::getActive() { + RsStackMutex stack(dhtMtx); return (mUdpBitDht->stateDht() >= BITDHT_MGR_STATE_ACTIVE); } bool p3BitDht::getNetworkStats(uint32_t &netsize, uint32_t &localnetsize) { + RsStackMutex stack(dhtMtx); netsize = mUdpBitDht->statsNetworkSize(); localnetsize = mUdpBitDht->statsBDVersionSize(); return true; @@ -197,6 +207,7 @@ bool p3BitDht::findPeer(std::string pid) bdStdPrintNodeId(std::cerr, &nid); std::cerr << std::endl; + RsStackMutex stack(dhtMtx); /* add in peer */ mUdpBitDht->addFindNode(&nid, BITDHT_QFLAGS_DO_IDLE); @@ -223,8 +234,11 @@ bool p3BitDht::dropPeer(std::string pid) bdStdPrintNodeId(std::cerr, &nid); std::cerr << std::endl; - /* remove in peer */ - mUdpBitDht->removeFindNode(&nid); + { + RsStackMutex stack(dhtMtx); + /* remove in peer */ + mUdpBitDht->removeFindNode(&nid); + } /* remove from translation */ if (!removeTranslation(pid))