59 void Constructed(
const PObject & mutex)
const;
60 void Destroyed(
const PObject & mutex)
const;
61 #define PMUTEX_CONSTRUCTED() Constructed(*this)
62 #define PMUTEX_DESTROYED() Destroyed(*this)
64 #define PMUTEX_CONSTRUCTED()
65 #define PMUTEX_DESTROYED()
68 void PrintOn(ostream &strm)
const;
152 virtual void PrintOn(ostream &strm)
const;
164 static unsigned CtorDtorLogLevel;
183 #include "msos/ptlib/mutex.h"
185 #include "unix/ptlib/mutex.h"
193 #define PDECLARE_MUTEX_ARG_1(var) struct PTimedMutex_##var : PTimedMutex { PTimedMutex_##var() : PTimedMutex(P_DEBUG_LOCATION) { } } var
194 #define PDECLARE_MUTEX_ARG_2(var,nam) struct PTimedMutex_##var : PTimedMutex { PTimedMutex_##var() : PTimedMutex(#nam ) { } } var
195 #define PDECLARE_MUTEX_ARG_3(var,nam,to) struct PTimedMutex_##var : PTimedMutex { PTimedMutex_##var() : PTimedMutex(#nam,to ) { } } var
197 #define PDECLARE_MUTEX_PART1(narg, args) PDECLARE_MUTEX_PART2(narg, args)
198 #define PDECLARE_MUTEX_PART2(narg, args) PDECLARE_MUTEX_ARG_##narg args
200 #define PDECLARE_MUTEX(...) PDECLARE_MUTEX_PART1(PARG_COUNT(__VA_ARGS__), (__VA_ARGS__))
207 const char * baseName,
210 const char * waitName,
211 const char * heldName,
214 unsigned throttleTime = 10000,
215 unsigned throttledLogLevel = 2,
216 unsigned unthrottledLogLevel = 6,
217 unsigned thresholdPercent = 5,
218 unsigned maxHistory = 0
221 , m_timeWaitContext(
PDebugLocation(file, line, waitName), waitTime, throttleTime, throttledLogLevel, unthrottledLogLevel, thresholdPercent, maxHistory)
222 , m_timeHeldContext(
PDebugLocation(file, line, heldName), heldTime, throttleTime, throttledLogLevel, unthrottledLogLevel, thresholdPercent, maxHistory)
225 void SetWaitThrottleTime(
unsigned throttleTime) { m_timeWaitContext.SetThrottleTime(throttleTime); }
226 void SetWaitThrottledLogLevel(
unsigned throttledLogLevel) { m_timeWaitContext.SetThrottledLogLevel(throttledLogLevel); }
227 void SetWaitUnthrottledLogLevel(
unsigned unthrottledLogLevel) { m_timeWaitContext.SetUnthrottledLogLevel(unthrottledLogLevel); }
228 void SetWaitThresholdPercent(
unsigned thresholdPercent) { m_timeWaitContext.SetThresholdPercent(thresholdPercent); }
229 void SetWaitMaxHistory(
unsigned maxHistory) { m_timeWaitContext.SetMaxHistory(maxHistory); }
231 void SetHeldThrottleTime(
unsigned throttleTime) { m_timeHeldContext.SetThrottleTime(throttleTime); }
232 void SetHeldThrottledLogLevel(
unsigned throttledLogLevel) { m_timeHeldContext.SetThrottledLogLevel(throttledLogLevel); }
233 void SetHeldUnthrottledLogLevel(
unsigned unthrottledLogLevel) { m_timeHeldContext.SetUnthrottledLogLevel(unthrottledLogLevel); }
234 void SetHeldThresholdPercent(
unsigned thresholdPercent) { m_timeHeldContext.SetThresholdPercent(thresholdPercent); }
235 void SetHeldMaxHistory(
unsigned maxHistory) { m_timeHeldContext.SetMaxHistory(maxHistory); }
248 #define PDECLARE_INSTRUMENTED_MUTEX(var, name, ...) \
249 struct PInstrumentedMutex_##name : PInstrumentedMutex { \
250 PInstrumentedMutex_##name(const char * mutexName = #name) \
251 : PInstrumentedMutex(mutexName, __FILE__, __LINE__, \
252 "Wait " #name, "Held " #name, \
257 #define PDECLARE_INSTRUMENTED_MUTEX(var, name, waitTime, heldTime, ...) \
258 PDECLARE_MUTEX(var, name, MinDeadlockTime(waitTime))
331 mutable CRITICAL_SECTION criticalSection;
332 #elif defined(P_PTHREADS) || defined(VX_TASKS)
333 mutable pthread_mutex_t m_mutex;
338 #endif // PTLIB_MUTEX_H
void Construct(unsigned timeout)
Information about a source file location.
Definition: object.h:333
unsigned m_excessiveLockTimeout
Definition: mutex.h:45
atomic< bool > m_excessiveLockActive
Definition: mutex.h:46
bool InternalSignal(const PDebugLocation *location)
PObject * Clone() const
Create a new PCriticalSection.
Definition: mutex.h:300
unsigned m_lockCount
Definition: mutex.h:171
PCriticalSection & operator=(const PCriticalSection &)
Assignment operator is allowed but does nothing.
Definition: mutex.h:293
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
void InternalWait(const PDebugLocation *location)
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
const char * m_extra
Definition: object.h:337
bool Try()
Try to enter the critical section for exlusive access.
This class implements critical section mutexes using the most efficient mechanism available on the ho...
Definition: mutex.h:270
PDebugLocation(const char *extra=NULL)
Definition: object.h:339
#define PINLINE
Definition: object.h:194
virtual void ReleasedLock(const PObject &mutex, uint64_t startHeldSamplePoint, bool readOnly, const PDebugLocation &location)
virtual void Signal()
Leave the critical section by unlocking the mutex.
void PlatformSignal(const PDebugLocation *location)
PTimedMutex & operator=(const PTimedMutex &)
Assignment operator is allowed but does nothing.
Definition: mutex.h:125
PMutexExcessiveLockInfo()
static DeadlockStackWalkModes DeadlockStackWalkMode
Definition: mutex.h:162
void InternalWaitComplete(uint64_t startWaitCycle, const PDebugLocation *location)
PCriticalSection()
Create a new critical section object .
~PCriticalSection()
Destroy the critical section object.
static unsigned ExcessiveLockWaitTime
Definition: mutex.h:154
bool PlatformWait(const PTimeInterval &timeout)
void Enter()
Definition: mutex.h:308
void SetLocationName(const char *name)
Definition: mutex.h:76
bool PBoolean
Definition: object.h:174
This class, along with the PPROFILE_TIMESCOPE() macro, allows the measurement of the time used by a s...
Definition: object.h:1430
void ExcessiveLockPhantom(const PObject &mutex) const
PThreadIdentifier m_lockerId
Definition: mutex.h:168
void Leave()
Definition: mutex.h:322
This class defines a thread mutual exclusion object.
Definition: mutex.h:101
virtual void Signal()
Signal that the synchronisation object is available.
PUniqueThreadIdentifier m_lastUniqueId
Definition: mutex.h:170
uint64_t m_startHeldSamplePoint
Definition: mutex.h:47
virtual void AcquiredLock(uint64_t startWaitCycle, bool readOnly, const PDebugLocation &location)
DeadlockStackWalkModes
Definition: mutex.h:155
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
PDebugLocation m_location
Definition: mutex.h:44
~PTimedMutex()
Destruction.
virtual ~PMutexExcessiveLockInfo()
Definition: mutex.h:55
Definition: object.h:1537
PThreadIdentifier m_lastLockerId
Definition: mutex.h:169
virtual bool InstrumentedWait(const PTimeInterval &timeout, const PDebugLocation &)
As for Wait() but with location of call for instrumentation. Mostly used internally.
Definition: psync.h:66
PINLINE bool Try()
Try to enter the critical section for exlusive access.
Definition: mutex.h:150
virtual void Wait()
Enter the critical section by waiting for exclusive access.
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
void PrintOn(ostream &strm) const
virtual void InstrumentedSignal(const PDebugLocation &)
As for Signal() but with location of call for instrumentation. Mostly used internally.
Definition: psync.h:73
static unsigned MinDeadlockTime(unsigned waitTime)
PTimedMutex PMutex
Definition: mutex.h:189
virtual void Wait()
Block until the synchronisation object is available.