mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -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
@ -63,7 +63,7 @@ std::ostream &operator<<(std::ostream &out, const CacheData &d)
|
||||
********************************* Cache Store / Source *************************/
|
||||
|
||||
CacheSource::CacheSource(uint16_t t, bool m, CacheStrapper *cs, std::string cachedir)
|
||||
:cacheType(t), multiCache(m), mStrapper(cs), cacheDir(cachedir)
|
||||
:cacheType(t), multiCache(m), mStrapper(cs), cacheDir(cachedir), cMutex("CacheSource")
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -218,7 +218,7 @@ void CacheSource::listCaches(std::ostream &out)
|
||||
CacheStore::CacheStore(uint16_t t, bool m,
|
||||
CacheStrapper *cs, CacheTransfer *cft, std::string cachedir)
|
||||
:cacheType(t), multiCache(m), mStrapper(cs),
|
||||
cacheTransfer(cft), cacheDir(cachedir)
|
||||
cacheTransfer(cft), cacheDir(cachedir), cMutex("CacheStore")
|
||||
{
|
||||
/* not much */
|
||||
return;
|
||||
@ -543,7 +543,7 @@ void CacheStore::locked_storeCacheEntry(const CacheData &data)
|
||||
********************************* CacheStrapper ********************************/
|
||||
|
||||
CacheStrapper::CacheStrapper(p3ConnectMgr *cm)
|
||||
:p3Config(CONFIG_TYPE_CACHE), mConnMgr(cm)
|
||||
:p3Config(CONFIG_TYPE_CACHE), mConnMgr(cm), csMtx("CacheStrapper")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@
|
||||
// ***********/
|
||||
|
||||
FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid,const std::string& config_dir)
|
||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
||||
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fiMutex("FileIndexMonitor"), fi(pid),
|
||||
pendingDirs(false), pendingForceCacheWrite(false),
|
||||
mForceCheck(false), mInCheck(false),cb(cb_in), hashCache(config_dir+"/" + "file_cache.lst"),useHashCache(true)
|
||||
|
||||
|
@ -50,7 +50,7 @@ static const char FILE_CACHE_SEPARATOR_CHAR = '|' ;
|
||||
* #define FI_DEBUG_ALL 1
|
||||
****/
|
||||
|
||||
static RsMutex FIndexPtrMtx ;
|
||||
static RsMutex FIndexPtrMtx("FIndexPtrMtx") ;
|
||||
std::tr1::unordered_set<void*> FileIndex::_pointers ;
|
||||
|
||||
void FileIndex::registerEntry(void*p)
|
||||
|
@ -72,7 +72,7 @@ virtual int dhtConnectCallback(const bdId *srcId, const bdId *proxyId, const bdI
|
||||
|
||||
|
||||
p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, UdpStack *udpstack, std::string bootstrapfile)
|
||||
:pqiNetAssistConnect(id, cb)
|
||||
:pqiNetAssistConnect(id, cb), dhtMtx("p3BitDht")
|
||||
{
|
||||
std::string dhtVersion = "RS51"; // should come from elsewhere!
|
||||
bdNodeId ownId;
|
||||
|
@ -100,6 +100,8 @@ ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string c
|
||||
last_clean_time(0),
|
||||
mDataplex(dm),
|
||||
mTurtle(NULL),
|
||||
ctrlMutex("ftController"),
|
||||
doneMutex("ftController"),
|
||||
mFtActive(false),
|
||||
mDefaultChunkStrategy(FileChunksInfo::CHUNK_STRATEGY_RANDOM)
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ ftRequest::ftRequest(uint32_t type, std::string peerId, std::string hash, uint64
|
||||
}
|
||||
|
||||
ftDataMultiplex::ftDataMultiplex(std::string ownId, ftDataSend *server, ftSearch *search)
|
||||
:RsQueueThread(DMULTIPLEX_MIN, DMULTIPLEX_MAX, DMULTIPLEX_RELAX),
|
||||
:RsQueueThread(DMULTIPLEX_MIN, DMULTIPLEX_MAX, DMULTIPLEX_RELAX), dataMtx("ftDataMultiplex"),
|
||||
mDataSend(server), mSearch(search), mOwnId(ownId)
|
||||
{
|
||||
return;
|
||||
|
@ -37,7 +37,7 @@
|
||||
*****/
|
||||
|
||||
ftExtraList::ftExtraList()
|
||||
:p3Config(CONFIG_TYPE_FT_EXTRA_LIST)
|
||||
:p3Config(CONFIG_TYPE_FT_EXTRA_LIST), extMutex("p3Config")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
static const time_t UPLOAD_CHUNK_MAPS_TIME = 20 ; // time to ask for a new chunkmap from uploaders in seconds.
|
||||
|
||||
ftFileProvider::ftFileProvider(const std::string& path, uint64_t size, const std::string& hash)
|
||||
: mSize(size), hash(hash), file_name(path), fd(NULL)
|
||||
: mSize(size), hash(hash), file_name(path), fd(NULL), ftcMutex("ftFileProvider")
|
||||
{
|
||||
RsStackMutex stack(ftcMutex); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -63,7 +63,7 @@ ftServer::ftServer(p3ConnectMgr *connMgr)
|
||||
mCacheStrapper(NULL),
|
||||
mFiStore(NULL), mFiMon(NULL),
|
||||
mFtController(NULL), mFtExtra(NULL),
|
||||
mFtDataplex(NULL), mFtSearch(NULL)
|
||||
mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer")
|
||||
{
|
||||
mCacheStrapper = new ftCacheStrapper(connMgr);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ const uint32_t FT_TM_CRC_MAP_STATE_HAVE = 2 ;
|
||||
#define FT_TM_FLAG_CHUNK_CRC 4
|
||||
|
||||
ftTransferModule::ftTransferModule(ftFileCreator *fc, ftDataMultiplex *dm, ftController *c)
|
||||
:mFileCreator(fc), mMultiplexor(dm), mFtController(c), mFlag(FT_TM_FLAG_DOWNLOADING)
|
||||
:mFileCreator(fc), mMultiplexor(dm), mFtController(c), tfMtx("ftTransferModule"), mFlag(FT_TM_FLAG_DOWNLOADING)
|
||||
{
|
||||
RsStackMutex stack(tfMtx); /******* STACK LOCKED ******/
|
||||
|
||||
@ -518,7 +518,7 @@ class HashThread: public RsThread
|
||||
{
|
||||
public:
|
||||
HashThread(ftFileCreator *m)
|
||||
: _m(m),_finished(false),_hash("") {}
|
||||
: _hashThreadMtx("HashThread"), _m(m),_finished(false),_hash("") {}
|
||||
|
||||
virtual void run()
|
||||
{
|
||||
|
@ -134,7 +134,7 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
|
||||
}
|
||||
|
||||
AuthGPGimpl::AuthGPGimpl()
|
||||
:p3Config(CONFIG_TYPE_AUTHGPG),gpgmeInit(false),gpgmeKeySelected(false)
|
||||
:p3Config(CONFIG_TYPE_AUTHGPG), gpgMtxEngine("AuthGPG-engine"), gpgMtxData("AuthGPG-data"),gpgmeInit(false),gpgmeKeySelected(false), gpgMtxService("AuthGPG-service")
|
||||
{
|
||||
{
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
@ -123,8 +123,8 @@ sslcert::sslcert(X509 *x509, std::string pid)
|
||||
|
||||
|
||||
AuthSSLimpl::AuthSSLimpl()
|
||||
: p3Config(CONFIG_TYPE_AUTHSSL), sslctx(NULL),
|
||||
mOwnCert(NULL), mOwnPrivateKey(NULL), mOwnPublicKey(NULL), init(0)
|
||||
: p3Config(CONFIG_TYPE_AUTHSSL), sslctx(NULL),
|
||||
mOwnCert(NULL), sslMtx("AuthSSL"), mOwnPrivateKey(NULL), mOwnPublicKey(NULL), init(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@
|
||||
|
||||
|
||||
p3ConfigMgr::p3ConfigMgr(std::string dir, std::string fname, std::string signame)
|
||||
:basedir(dir), metafname(fname), metasigfname(signame),
|
||||
:basedir(dir), metafname(fname), metasigfname(signame), cfgMtx("p3ConfigMgr"),
|
||||
mConfigSaveActive(true)
|
||||
{
|
||||
oldConfigType = checkForGlobalSigConfig();
|
||||
@ -1295,7 +1295,7 @@ bool p3GeneralConfig::loadList(std::list<RsItem *>& load)
|
||||
bool pqiConfig::globalConfigType = false;
|
||||
|
||||
pqiConfig::pqiConfig(uint32_t t)
|
||||
:ConfInd(2), type(t)
|
||||
: cfgMtx("pqiConfig"), ConfInd(2), type(t)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ void pqiNetStatus::print(std::ostream &out)
|
||||
|
||||
|
||||
p3ConnectMgr::p3ConnectMgr()
|
||||
:p3Config(CONFIG_TYPE_PEERS),
|
||||
:p3Config(CONFIG_TYPE_PEERS), connMtx("p3ConnectMgr"),
|
||||
mNetStatus(RS_NET_UNKNOWN),
|
||||
mStatusChanged(false)
|
||||
{
|
||||
|
@ -89,7 +89,7 @@ dhtPeerEntry::dhtPeerEntry()
|
||||
}
|
||||
|
||||
p3DhtMgr::p3DhtMgr(std::string id, pqiConnectCb *cb)
|
||||
:pqiNetAssistConnect(id, cb), mStunRequired(true)
|
||||
:pqiNetAssistConnect(id, cb), dhtMtx("p3DhtMgr"), mStunRequired(true)
|
||||
{
|
||||
/* setup own entry */
|
||||
dhtMtx.lock(); /* LOCK MUTEX */
|
||||
|
@ -66,7 +66,7 @@ class p3Notify: public RsNotify, public pqiNotify
|
||||
{
|
||||
public:
|
||||
|
||||
p3Notify() { return; }
|
||||
p3Notify() : noteMtx("p3Notify") { return; }
|
||||
virtual ~p3Notify() { return; }
|
||||
|
||||
/* Output for retroshare-gui */
|
||||
|
@ -38,7 +38,7 @@ const int pqihandlerzone = 34283;
|
||||
#define RSITEM_DEBUG 1
|
||||
****/
|
||||
|
||||
pqihandler::pqihandler(SecurityPolicy *Global)
|
||||
pqihandler::pqihandler(SecurityPolicy *Global) : coreMtx("pqihandler")
|
||||
{
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
|
||||
|
@ -33,7 +33,7 @@ const int pqiservicezone = 60478;
|
||||
* #define SERVICE_DEBUG 1
|
||||
****/
|
||||
|
||||
p3ServiceServer::p3ServiceServer()
|
||||
p3ServiceServer::p3ServiceServer() : srvMtx("p3ServiceServer")
|
||||
{
|
||||
RsStackMutex stack(srvMtx); /********* LOCKED *********/
|
||||
|
||||
|
@ -58,7 +58,7 @@ pqistreamer::pqistreamer(RsSerialiser *rss, std::string id, BinInterface *bio_in
|
||||
pkt_wpending(NULL),
|
||||
totalRead(0), totalSent(0),
|
||||
currRead(0), currSent(0),
|
||||
avgReadCount(0), avgSentCount(0)
|
||||
avgReadCount(0), avgSentCount(0), streamerMtx("pqistreamer")
|
||||
{
|
||||
avgLastUpdate = currReadTS = currSentTS = time(NULL);
|
||||
|
||||
|
@ -40,7 +40,7 @@
|
||||
****/
|
||||
|
||||
RsServer::RsServer(RsIface &i, NotifyBase &callback)
|
||||
:RsControl(i, callback)
|
||||
:RsControl(i, callback), coreMutex("RsServer")
|
||||
{
|
||||
ftserver = NULL;
|
||||
|
||||
|
@ -80,7 +80,7 @@ class RsIfaceReal: public RsIface
|
||||
{
|
||||
public:
|
||||
RsIfaceReal(NotifyBase &callback)
|
||||
:RsIface(callback)
|
||||
:RsIface(callback), rsIfaceMutex("RsIface")
|
||||
{ return; }
|
||||
|
||||
virtual void lockData()
|
||||
|
@ -42,7 +42,7 @@
|
||||
*/
|
||||
|
||||
p3ChatService::p3ChatService(p3ConnectMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mConnMgr(cm)
|
||||
:p3Service(RS_SERVICE_TYPE_CHAT), p3Config(CONFIG_TYPE_CHAT), mChatMtx("p3ChatService"), mConnMgr(cm)
|
||||
{
|
||||
addSerialType(new RsChatSerialiser());
|
||||
|
||||
|
@ -86,7 +86,7 @@ p3disc::p3disc(p3ConnectMgr *cm, pqipersongrp *pqih)
|
||||
:p3Service(RS_SERVICE_TYPE_DISC),
|
||||
p3Config(CONFIG_TYPE_P3DISC),
|
||||
mConnMgr(cm),
|
||||
mPqiPersonGrp(pqih)
|
||||
mPqiPersonGrp(pqih), mDiscMtx("p3disc")
|
||||
{
|
||||
RsStackMutex stack(mDiscMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -105,7 +105,7 @@ p3GroupDistrib::p3GroupDistrib(uint16_t subtype,
|
||||
:CacheSource(subtype, true, cs, sourcedir),
|
||||
CacheStore(subtype, true, cs, cft, storedir),
|
||||
p3Config(configId), p3ThreadedService(subtype),
|
||||
mHistoricalCaches(true),
|
||||
mHistoricalCaches(true), distribMtx(""),
|
||||
mStorePeriod(storePeriod),
|
||||
mPubPeriod(pubPeriod),
|
||||
mLastPublishTime(0),
|
||||
@ -119,9 +119,14 @@ p3GroupDistrib::p3GroupDistrib(uint16_t subtype,
|
||||
mLastCacheDocUpdate = time(NULL);
|
||||
mHistoricalCachesLoaded = false;
|
||||
|
||||
mOwnId = AuthSSL::getAuthSSL()->OwnId();
|
||||
#ifdef RSMUTEX_DEBUG
|
||||
distribMtx.setName("p3GroupDistrib - " + keyBackUpDir.substr(keyBackUpDir.find_last_of('/') + 1));
|
||||
#endif
|
||||
|
||||
mOwnId = AuthSSL::getAuthSSL()->OwnId();
|
||||
|
||||
addSerialType(new RsDistribSerialiser(getRsItemService(getType())));
|
||||
|
||||
addSerialType(new RsDistribSerialiser(getRsItemService(getType())));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ const int msgservicezone = 54319;
|
||||
|
||||
p3MsgService::p3MsgService(p3ConnectMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS),
|
||||
mConnMgr(cm), msgChanged(1), mMsgUniqueId(1)
|
||||
mConnMgr(cm), mMsgMtx("p3MsgService"), msgChanged(1), mMsgUniqueId(1)
|
||||
{
|
||||
addSerialType(new RsMsgSerialiser());
|
||||
|
||||
|
@ -49,7 +49,7 @@ PhotoSet::PhotoSet()
|
||||
p3PhotoService::p3PhotoService(uint16_t type, CacheStrapper *cs, CacheTransfer *cft,
|
||||
std::string sourcedir, std::string storedir)
|
||||
:CacheSource(type, true, cs, sourcedir),
|
||||
CacheStore(type, true, cs, cft, storedir),
|
||||
CacheStore(type, true, cs, cft, storedir), mPhotoMtx("p3PhotoService"),
|
||||
mUpdated(true)
|
||||
{
|
||||
|
||||
|
@ -58,7 +58,7 @@ class p3Service: public pqiService
|
||||
|
||||
p3Service(uint16_t type)
|
||||
:pqiService((((uint32_t) RS_PKT_VERSION_SERVICE) << 24) + (((uint32_t) type) << 8)),
|
||||
rsSerialiser(NULL)
|
||||
srvMtx("p3Service"), rsSerialiser(NULL)
|
||||
{
|
||||
rsSerialiser = new RsSerialiser();
|
||||
return;
|
||||
|
@ -44,7 +44,7 @@ std::ostream& operator<<(std::ostream& out, const StatusInfo& si)
|
||||
RsStatus *rsStatus = NULL;
|
||||
|
||||
p3StatusService::p3StatusService(p3ConnectMgr *cm)
|
||||
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mConnMgr(cm)
|
||||
:p3Service(RS_SERVICE_TYPE_STATUS), p3Config(CONFIG_TYPE_STATUS), mConnMgr(cm), mStatusMtx("p3StatusService")
|
||||
{
|
||||
addSerialType(new RsStatusSerialiser());
|
||||
|
||||
|
@ -72,7 +72,7 @@ static const double RTT_ALPHA = 0.875;
|
||||
static double getCurrentTS();
|
||||
|
||||
TcpStream::TcpStream(UdpSubReceiver *lyr)
|
||||
:inSize(0), outSizeRead(0), outSizeNet(0),
|
||||
: tcpMtx("TcpStream"), inSize(0), outSizeRead(0), outSizeNet(0),
|
||||
state(TCP_CLOSED),
|
||||
inStreamActive(false),
|
||||
outStreamActive(false),
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
|
||||
UdpPeerReceiver::UdpPeerReceiver(UdpPublisher *pub)
|
||||
:UdpSubReceiver(pub)
|
||||
:UdpSubReceiver(pub), peerMtx("UdpSubReceiver")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ int displayUdpRelayPacketHeader(const void *data, const int size);
|
||||
#define MAX_RELAY_UDP_PACKET_SIZE 1024
|
||||
|
||||
UdpRelayReceiver::UdpRelayReceiver(UdpPublisher *pub)
|
||||
:UdpSubReceiver(pub)
|
||||
:UdpSubReceiver(pub), udppeerMtx("UdpSubReceiver"), relayMtx("UdpSubReceiver")
|
||||
{
|
||||
mClassLimit.resize(UDP_RELAY_NUM_CLASS);
|
||||
mClassCount.resize(UDP_RELAY_NUM_CLASS);
|
||||
|
@ -48,7 +48,7 @@ const double TOU_SUCCESS_LPF_FACTOR = 0.90;
|
||||
|
||||
|
||||
UdpStunner::UdpStunner(UdpPublisher *pub)
|
||||
:UdpSubReceiver(pub), eaddrKnown(false), eaddrStable(false),
|
||||
:UdpSubReceiver(pub), stunMtx("UdpSubReceiver"), eaddrKnown(false), eaddrStable(false),
|
||||
mStunLastRecvResp(0), mStunLastRecvAny(0),
|
||||
mStunLastSendStun(0), mStunLastSendAny(0)
|
||||
{
|
||||
|
@ -88,7 +88,7 @@ static const uint32_t MAX_TUNNEL_REQS_PER_SECOND= 1 ; /// maximum number of t
|
||||
static const uint32_t MAX_ALLOWED_SR_IN_CACHE = 120 ; /// maximum number of search requests allowed in cache. That makes 2 per sec.
|
||||
|
||||
p3turtle::p3turtle(p3ConnectMgr *cm,ftServer *fs)
|
||||
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mConnMgr(cm)
|
||||
:p3Service(RS_SERVICE_TYPE_TURTLE), p3Config(CONFIG_TYPE_TURTLE), mConnMgr(cm), mTurtleMtx("p3turtle")
|
||||
{
|
||||
RsStackMutex stack(mTurtleMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
|
@ -840,7 +840,7 @@ bool upnphandler::shutdown_upnp()
|
||||
*/
|
||||
|
||||
upnphandler::upnphandler()
|
||||
:toEnable(false), toStart(false), toStop(false),
|
||||
: dataMtx("upnpState"), toEnable(false), toStart(false), toStop(false),
|
||||
eport(0), eport_curr(0),
|
||||
upnpState(RS_UPNP_S_UNINITIALISED),
|
||||
upnpConfig(NULL)
|
||||
|
@ -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 RSMUTEX_DEBUG
|
||||
void setName(const std::string &name)
|
||||
{
|
||||
#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
|
||||
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…
Reference in New Issue
Block a user