mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
enabled recursive lock behavior on main bitdht thread to handle self-lock in DHT callbacks
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3849 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
42fb103738
commit
8a3d3f8c0d
@ -51,7 +51,7 @@
|
|||||||
/*************************************/
|
/*************************************/
|
||||||
|
|
||||||
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, bdDhtFunctions *fns)
|
UdpBitDht::UdpBitDht(UdpPublisher *pub, bdNodeId *id, std::string appVersion, std::string bootstrapfile, bdDhtFunctions *fns)
|
||||||
:UdpSubReceiver(pub), mFns(fns)
|
:UdpSubReceiver(pub), dhtMtx(true), mFns(fns)
|
||||||
{
|
{
|
||||||
std::string usedVersion;
|
std::string usedVersion;
|
||||||
|
|
||||||
@ -210,6 +210,7 @@ void UdpBitDht::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||||
mBitDhtManager->iteration();
|
mBitDhtManager->iteration();
|
||||||
}
|
}
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
@ -36,14 +37,29 @@ class bdMutex
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bdMutex() { pthread_mutex_init(&realMutex, NULL); }
|
bdMutex(bool recursive = false)
|
||||||
~bdMutex() { pthread_mutex_destroy(&realMutex); }
|
{
|
||||||
void lock() { pthread_mutex_lock(&realMutex); }
|
if(recursive)
|
||||||
void unlock() { pthread_mutex_unlock(&realMutex); }
|
{
|
||||||
bool trylock() { return (0 == pthread_mutex_trylock(&realMutex)); }
|
pthread_mutexattr_t att ;
|
||||||
|
pthread_mutexattr_init(&att) ;
|
||||||
|
pthread_mutexattr_settype(&att,PTHREAD_MUTEX_RECURSIVE) ;
|
||||||
|
|
||||||
|
if( pthread_mutex_init(&realMutex, &att))
|
||||||
|
std::cerr << "ERROR: Could not initialize mutex !" << std::endl ;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if( pthread_mutex_init(&realMutex, NULL))
|
||||||
|
std::cerr << "ERROR: Could not initialize mutex !" << std::endl ;
|
||||||
|
}
|
||||||
|
|
||||||
|
~bdMutex() { pthread_mutex_destroy(&realMutex); }
|
||||||
|
void lock() { pthread_mutex_lock(&realMutex); }
|
||||||
|
void unlock() { pthread_mutex_unlock(&realMutex); }
|
||||||
|
bool trylock() { return (0 == pthread_mutex_trylock(&realMutex)); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pthread_mutex_t realMutex;
|
pthread_mutex_t realMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
class bdStackMutex
|
class bdStackMutex
|
||||||
|
Loading…
Reference in New Issue
Block a user