mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-20 03:48:16 -04:00
Added a name to the RsMutex class.
You can enable the debugging of the waiting time for a lock of RsMutex in rsthreads.h with #define RSMUTEX_DEBUG 300 That means all locks waiting longer than 300ms are logged into the stderr. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4392 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a94568ac33
commit
de87a89437
42 changed files with 103 additions and 64 deletions
|
@ -154,7 +154,7 @@ DNSResolver::~DNSResolver()
|
|||
delete _thread_running ;
|
||||
}
|
||||
|
||||
DNSResolver::DNSResolver()
|
||||
DNSResolver::DNSResolver() : _rdnsMtx("DNSResolver")
|
||||
{
|
||||
RsStackMutex mut(_rdnsMtx) ;
|
||||
|
||||
|
|
|
@ -271,7 +271,7 @@ ExtAddrFinder::~ExtAddrFinder()
|
|||
free (_addr) ;
|
||||
}
|
||||
|
||||
ExtAddrFinder::ExtAddrFinder()
|
||||
ExtAddrFinder::ExtAddrFinder() : _addrMtx("ExtAddrFinder")
|
||||
{
|
||||
#ifdef EXTADDRSEARCH_DEBUG
|
||||
std::cerr << "ExtAddrFinder: Creating new ExtAddrFinder." << std::endl ;
|
||||
|
|
|
@ -45,7 +45,7 @@ static int lineCount = 0;
|
|||
static std::string crashfile;
|
||||
static int debugTS = 0;
|
||||
|
||||
static RsMutex logMtx;
|
||||
static RsMutex logMtx("logMtx");
|
||||
|
||||
int locked_setDebugFile(const char *fname);
|
||||
int locked_getZoneLevel(int zone);
|
||||
|
|
|
@ -43,7 +43,7 @@ time_t RsDiscSpace::_last_check[3] = { 0,0,0 } ;
|
|||
uint32_t RsDiscSpace::_size_limit_mb = 100 ;
|
||||
uint32_t RsDiscSpace::_current_size[3] = { 10000,10000,10000 } ;
|
||||
bool RsDiscSpace::_last_res[3] = { true,true,true };
|
||||
RsMutex RsDiscSpace::_mtx ;
|
||||
RsMutex RsDiscSpace::_mtx("RsDiscSpace") ;
|
||||
|
||||
bool RsDiscSpace::crossSystemDiskStats(const char *file, uint64_t& free_blocks, uint64_t& block_size)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
uint32_t RSRandom::index = 0 ;
|
||||
std::vector<uint32_t> RSRandom::MT(RSRandom::N,0u) ;
|
||||
RsMutex RSRandom::rndMtx ;
|
||||
RsMutex RSRandom::rndMtx("RSRandom") ;
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
static bool auto_seed = RSRandom::seed( (time(NULL) + ((uint32_t) pthread_self().p)*0x1293fe)^0x18e34a12 ) ;
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
#include <errno.h> /* for usleep() */
|
||||
#include <iostream>
|
||||
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*******
|
||||
* #define DEBUG_THREADS 1
|
||||
*******/
|
||||
|
@ -86,7 +90,7 @@ pthread_t createThread(RsThread &thread)
|
|||
|
||||
}
|
||||
|
||||
RsThread::RsThread ()
|
||||
RsThread::RsThread () : mMutex("RsThread")
|
||||
{
|
||||
mIsRunning = true;
|
||||
|
||||
|
@ -169,3 +173,30 @@ void RsQueueThread::run()
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void RsMutex::lock()
|
||||
{
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
clock_t t1 = clock();
|
||||
#endif
|
||||
|
||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
if(!trylock())
|
||||
if(!pthread_equal(_thread_id,pthread_self()))
|
||||
#endif
|
||||
pthread_mutex_lock(&realMutex);
|
||||
|
||||
_thread_id = pthread_self() ;
|
||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
++_cnt ;
|
||||
#endif
|
||||
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
clock_t t2 = clock();
|
||||
double duration = (double) (t2 - t1) / CLOCKS_PER_SEC;
|
||||
if (duration * 1000 > RSMUTEX_DEBUG) {
|
||||
fprintf(stderr, "RsMutex::lock() %s --> %.3fs\n", name.c_str(), duration);
|
||||
fflush(stderr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -37,16 +37,20 @@
|
|||
/* RsIface Thread Wrappers */
|
||||
|
||||
#undef RSTHREAD_SELF_LOCKING_GUARD
|
||||
//#define RSMUTEX_DEBUG 300 // Milliseconds for print in the stderr
|
||||
|
||||
class RsMutex
|
||||
{
|
||||
public:
|
||||
|
||||
RsMutex()
|
||||
{
|
||||
RsMutex(const std::string &name)
|
||||
{
|
||||
pthread_mutex_init(&realMutex, NULL);
|
||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
_thread_id = 0 ;
|
||||
#endif
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
this->name = name;
|
||||
#endif
|
||||
}
|
||||
~RsMutex()
|
||||
|
@ -54,19 +58,14 @@ class RsMutex
|
|||
pthread_mutex_destroy(&realMutex);
|
||||
}
|
||||
|
||||
void lock()
|
||||
{
|
||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
if(!trylock())
|
||||
if(!pthread_equal(_thread_id,pthread_self()))
|
||||
#endif
|
||||
pthread_mutex_lock(&realMutex);
|
||||
|
||||
_thread_id = pthread_self() ;
|
||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
++_cnt ;
|
||||
#endif
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
void setName(const std::string &name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
#endif
|
||||
|
||||
void lock();
|
||||
void unlock()
|
||||
{
|
||||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
|
@ -89,6 +88,9 @@ class RsMutex
|
|||
#ifdef RSTHREAD_SELF_LOCKING_GUARD
|
||||
uint32_t _cnt ;
|
||||
#endif
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
std::string name;
|
||||
#endif
|
||||
};
|
||||
|
||||
class RsStackMutex
|
||||
|
@ -96,7 +98,7 @@ class RsStackMutex
|
|||
public:
|
||||
|
||||
RsStackMutex(RsMutex &mtx): mMtx(mtx) { mMtx.lock(); }
|
||||
~RsStackMutex() { mMtx.unlock(); }
|
||||
~RsStackMutex() { mMtx.unlock(); }
|
||||
|
||||
private:
|
||||
RsMutex &mMtx;
|
||||
|
@ -150,5 +152,4 @@ virtual bool doWork() = 0;
|
|||
float mRelaxFactor;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
using namespace RsMemoryManagement ;
|
||||
|
||||
RsMutex SmallObject::_mtx ;
|
||||
RsMutex SmallObject::_mtx("SmallObject") ;
|
||||
SmallObjectAllocator SmallObject::_allocator(RsMemoryManagement::MAX_SMALL_OBJECT_SIZE) ;
|
||||
|
||||
void Chunk::init(size_t blockSize,unsigned char blocks)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue