PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PTimedMutex Class Reference

This class defines a thread mutual exclusion object. More...

#include <mutex.h>

Inheritance diagram for PTimedMutex:
Collaboration diagram for PTimedMutex:

Public Types

enum  DeadlockStackWalkModes { DeadlockStackWalkDisabled, DeadlockStackWalkEnabled, DeadlockStackWalkOnPhantomRelease, DeadlockStackWalkNoSymbols }
 
- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 

Public Member Functions

 PTimedMutex ()
 
 PTimedMutex (const PDebugLocation &location, unsigned timeout=0)
 
 PTimedMutex (const PTimedMutex &mutex)
 Copy constructor is allowed but does not copy, allocating a new mutex. More...
 
PTimedMutexoperator= (const PTimedMutex &)
 Assignment operator is allowed but does nothing. More...
 
 ~PTimedMutex ()
 Destruction. More...
 
virtual void Wait ()
 Block until the synchronisation object is available. More...
 
virtual PBoolean Wait (const PTimeInterval &timeout)
 Block, for a time, until the synchronisation object is available. More...
 
virtual void Signal ()
 Signal that the synchronisation object is available. More...
 
PINLINE bool Try ()
 Try to enter the critical section for exlusive access. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
- Public Member Functions inherited from PSync
 PSync ()
 
virtual bool InstrumentedWait (const PTimeInterval &timeout, const PDebugLocation &)
 As for Wait() but with location of call for instrumentation. Mostly used internally. More...
 
virtual void InstrumentedSignal (const PDebugLocation &)
 As for Signal() but with location of call for instrumentation. Mostly used internally. More...
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 
- Public Member Functions inherited from PMutexExcessiveLockInfo
void SetLocationName (const char *name)
 

Static Public Attributes

static unsigned ExcessiveLockWaitTime
 
static DeadlockStackWalkModes DeadlockStackWalkMode
 

Protected Member Functions

void Construct ()
 
void PlatformConstruct ()
 
bool PlatformWait (const PTimeInterval &timeout)
 
void PlatformSignal (const PDebugLocation *location)
 
void InternalWait (const PDebugLocation *location)
 
void InternalWaitComplete (uint64_t startWaitCycle, const PDebugLocation *location)
 
bool InternalSignal (const PDebugLocation *location)
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 
- Protected Member Functions inherited from PMutexExcessiveLockInfo
 PMutexExcessiveLockInfo ()
 
 PMutexExcessiveLockInfo (const PDebugLocation &location, unsigned timeout)
 
 PMutexExcessiveLockInfo (const PMutexExcessiveLockInfo &other)
 
virtual ~PMutexExcessiveLockInfo ()
 
void Construct (unsigned timeout)
 
void PrintOn (ostream &strm) const
 
void ExcessiveLockPhantom (const PObject &mutex) const
 
virtual void AcquiredLock (uint64_t startWaitCycle, bool readOnly, const PDebugLocation &location)
 
virtual void ReleasedLock (const PObject &mutex, uint64_t startHeldSamplePoint, bool readOnly, const PDebugLocation &location)
 

Protected Attributes

PThreadIdentifier m_lockerId
 
PThreadIdentifier m_lastLockerId
 
PUniqueThreadIdentifier m_lastUniqueId
 
unsigned m_lockCount
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 
- Protected Attributes inherited from PMutexExcessiveLockInfo
PDebugLocation m_location
 
unsigned m_excessiveLockTimeout
 
atomic< bool > m_excessiveLockActive
 
uint64_t m_startHeldSamplePoint
 

Additional Inherited Members

- Static Public Member Functions inherited from PObject
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Static Protected Member Functions inherited from PMutexExcessiveLockInfo
static unsigned MinDeadlockTime (unsigned waitTime)
 

Detailed Description

This class defines a thread mutual exclusion object.

A mutex is where a piece of code or data cannot be accessed by more than one thread at a time. To prevent this the PMutex is used in the following manner:


      PMutex mutex;
      ...
      mutex.Wait();
      ... critical section - only one thread at a time here.
      mutex.Signal();
      ...

The first thread will pass through the Wait() function, a second thread will block on that function until the first calls the Signal() function, releasing the second thread.

Member Enumeration Documentation

Enumerator
DeadlockStackWalkDisabled 
DeadlockStackWalkEnabled 
DeadlockStackWalkOnPhantomRelease 
DeadlockStackWalkNoSymbols 

Constructor & Destructor Documentation

PTimedMutex::PTimedMutex ( )
explicit
PTimedMutex::PTimedMutex ( const PDebugLocation location,
unsigned  timeout = 0 
)
explicit
Parameters
locationSource file/line of mutex definition
timeoutTimeout in ms, before declaring a possible deadlock. Zero uses default.
PTimedMutex::PTimedMutex ( const PTimedMutex mutex)

Copy constructor is allowed but does not copy, allocating a new mutex.

Two copies of the same mutex information would be very bad.

PTimedMutex::~PTimedMutex ( )

Destruction.

Member Function Documentation

void PTimedMutex::Construct ( )
protected
bool PTimedMutex::InternalSignal ( const PDebugLocation location)
protected
void PTimedMutex::InternalWait ( const PDebugLocation location)
protected
void PTimedMutex::InternalWaitComplete ( uint64_t  startWaitCycle,
const PDebugLocation location 
)
protected
PTimedMutex& PTimedMutex::operator= ( const PTimedMutex )
inline

Assignment operator is allowed but does nothing.

Overwriting the old mutex information would be very bad.

void PTimedMutex::PlatformConstruct ( )
protected
void PTimedMutex::PlatformSignal ( const PDebugLocation location)
protected
bool PTimedMutex::PlatformWait ( const PTimeInterval timeout)
protected
virtual void PTimedMutex::PrintOn ( ostream &  strm) const
virtual

Output the contents of the object to the stream.

The exact output is dependent on the exact semantics of the descendent class. This is primarily used by the standard operator<< function.

The default behaviour is to print the class name.

Reimplemented from PObject.

Reimplemented in PIntCondMutex.

PINLINE bool PTimedMutex::Try ( )
inline

Try to enter the critical section for exlusive access.

Does not wait.

Returns
true if cirical section entered, leave/Signal must be called.

References Wait().

virtual PBoolean PTimedMutex::Wait ( const PTimeInterval timeout)
virtual

Block, for a time, until the synchronisation object is available.

Returns
true if lock is acquired, false if timed out

Implements PSync.

Member Data Documentation

DeadlockStackWalkModes PTimedMutex::DeadlockStackWalkMode
static
unsigned PTimedMutex::ExcessiveLockWaitTime
static
PThreadIdentifier PTimedMutex::m_lastLockerId
protected
PUniqueThreadIdentifier PTimedMutex::m_lastUniqueId
protected
unsigned PTimedMutex::m_lockCount
protected
PThreadIdentifier PTimedMutex::m_lockerId
protected

The documentation for this class was generated from the following file: