31 #ifndef PTLIB_CRITICALSECTION_H
32 #define PTLIB_CRITICALSECTION_H
36 #if defined(SOLARIS) && !defined(__GNUC__)
43 # if __GNUC__ >= 4 && __GNUC_MINOR__ >= 2
44 # include <ext/atomicity.h>
46 # include <bits/atomicity.h>
50 #if P_NEEDS_GNU_CXX_NAMESPACE
51 #define EXCHANGE_AND_ADD(v,i) __gnu_cxx::__exchange_and_add(v,i)
53 #define EXCHANGE_AND_ADD(v,i) __exchange_and_add(v,i)
56 #endif // P_HAS_ATOMIC_INT
105 inline void Enter() {
Wait(); }
110 inline void Leave() {
Signal(); }
119 #include "msos/ptlib/critsec.h"
133 #elif defined(_STLP_INTERNAL_THREADS_H) && defined(_STLP_ATOMIC_INCREMENT) && defined(_STLP_ATOMIC_DECREMENT)
135 #elif defined(SOLARIS) && !defined(__GNUC__)
137 #elif defined(__GNUC__) && P_HAS_ATOMIC_INT
251 __inline
operator bool()
const {
return m_value != 0; }
268 return strm << (b.
m_value != 0 ?
"true" :
"false");
273 #if defined(_WIN32) || defined(DOC_PLUS_PLUS)
281 #elif defined(_STLP_INTERNAL_THREADS_H) && defined(_STLP_ATOMIC_INCREMENT) && defined(_STLP_ATOMIC_DECREMENT)
289 #elif defined(SOLARIS) && !defined(__GNUC__)
297 #elif defined(__GNUC__) && P_HAS_ATOMIC_INT
316 #endif // PTLIB_CRITICALSECTION_H
friend __inline ostream & operator<<(ostream &strm, const PAtomicInteger &i)
Definition: critsec.h:204
int IntegerType
Definition: critsec.h:140
This class waits for the semaphore on construction and automatically signals the semaphore on destruc...
Definition: psync.h:86
virtual void Wait()=0
Block until the synchronisation object is available.
__inline bool operator!() const
Test if atomic integer has a non-zero value.
Definition: critsec.h:202
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
pthread_mutex_t m_mutex
Definition: critsec.h:142
Definition: critsec.h:128
__inline PAtomicBoolean & operator=(bool value)
Assign a value to the atomic boolean.
Definition: critsec.h:257
void SetValue(IntegerType value)
Set the value of the atomic integer.
Definition: critsec.h:189
PWaitAndSignal PEnterAndLeave
This class implements critical section mutexes using the most efficient mechanism available on the ho...
Definition: critsec.h:125
This class implements an atomic "test and set" boolean.
Definition: critsec.h:241
__inline PAtomicInteger & operator=(IntegerType value)
Assign a value to the atomic integer.
Definition: critsec.h:186
This class implements an integer that can be atomically incremented and decremented in a thread-safe ...
Definition: critsec.h:171
~PAtomicBase()
Destroy the atomic integer.
Definition: critsec.h:275
IntegerType m_value
Definition: critsec.h:146
__inline bool IsZero() const
Test if an atomic integer has a zero value.
Definition: critsec.h:199
IntegerType operator++()
atomically pre-increment the integer value
Definition: critsec.h:276
IntegerType operator--()
atomically pre-decrement the integer value
Definition: critsec.h:278
PAtomicBase(IntegerType value)
Definition: critsec.h:274
__inline bool operator!() const
Test if atomic integer has a non-zero value.
Definition: critsec.h:254
virtual void Signal()=0
Signal that the synchronisation object is available.
PAtomicInteger(IntegerType value=0)
Create a PAtomicInteger with the specified initial value.
Definition: critsec.h:178
PAtomicBoolean(bool value=false)
Create a PAtomicBoolean with the specified initial value.
Definition: critsec.h:246
bool TestAndSet(bool value)
Test Set the value of the atomic boolean.
Definition: critsec.h:280
#define PCriticalSection
Definition: mutex.h:115
virtual PObject * Clone() const
Create a copy of the class on the heap.
PAtomicBase::IntegerType IntegerType
Definition: critsec.h:174
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
friend __inline ostream & operator<<(ostream &strm, const PAtomicBoolean &b)
Definition: critsec.h:266