27#ifndef NIDAS_UTIL_THREADSUPPORT_H
28#define NIDAS_UTIL_THREADSUPPORT_H
37namespace nidas {
namespace util {
79#ifdef PTHREAD_PRIO_INHERIT
88 void setPriorityCeiling(
int val)
throw(
Exception);
89 int getPriorityCeiling()
const;
92#ifdef PTHREAD_PRIO_INHERIT
98 void setProtocol(
int val)
throw(
Exception);
99 int getProtocol()
const;
113 pthread_mutexattr_t*
ptr()
149 pthread_rwlockattr_t*
ptr()
177 explicit Mutex(
int type=PTHREAD_MUTEX_DEFAULT)
throw();
219 if((res = ::pthread_mutex_lock(&
_p_mutex)))
233 if ((res = ::pthread_mutex_unlock(&
_p_mutex)))
240 pthread_mutex_t*
ptr();
332 if ((res = ::pthread_cond_signal (&
_p_cond)))
344 if ((res = ::pthread_cond_broadcast (&
_p_cond)))
414 if ((res = ::pthread_rwlock_rdlock(&
_p_rwlock)))
427 if ((res = ::pthread_rwlock_wrlock(&
_p_rwlock)))
440 if ((res = ::pthread_rwlock_unlock(&
_p_rwlock)))
447 pthread_rwlock_t*
ptr();
501 return sem_trywait(&
_sem) == 0;
524 sem_getvalue(&
_sem,&val);
554 void sync(std::string& msg);
Autolock for acquiring/releasing a read lock on a RWLock.
Definition ThreadSupport.h:672
AutoRdLock(const Autolock &)
AutoRdLock(RWLock &rwlock)
Construct the guard object and lock() the lock.
Definition ThreadSupport.h:680
~AutoRdLock()
On destruction, unlock the lock.
Definition ThreadSupport.h:688
AutoRdLock & operator=(const Autolock &)
RWLock & _rwlock
Definition ThreadSupport.h:694
Autolock for acquiring/releasing a write lock on a RWLock.
Definition ThreadSupport.h:705
AutoWrLock & operator=(const Autolock &)
AutoWrLock(RWLock &rwlock)
Construct the guard object and lock() the lock.
Definition ThreadSupport.h:713
RWLock & _rwlock
Definition ThreadSupport.h:727
~AutoWrLock()
On destruction, unlock the lock.
Definition ThreadSupport.h:721
AutoWrLock(const Autolock &)
Autolock is used a simple guard object for critical sections.
Definition ThreadSupport.h:627
Cond * _condp
Definition ThreadSupport.h:660
Autolock(Cond &cond)
Construct the guard object and lock() the lock.
Definition ThreadSupport.h:635
~Autolock()
On destruction, unlock the lock.
Definition ThreadSupport.h:652
Mutex * _mutexp
Definition ThreadSupport.h:659
Autolock(Mutex &mutex)
Construct the guard object and lock() the lock.
Definition ThreadSupport.h:644
Autolock & operator=(const Autolock &)
Autolock(const Autolock &)
A wrapper class for a Posix condition variable.
Definition ThreadSupport.h:258
void lock()
Lock the mutex associated with the condition variable.
Definition ThreadSupport.h:304
pthread_cond_t _p_cond
Definition ThreadSupport.h:369
void broadcast()
Restart all threads waiting on the condition variable.
Definition ThreadSupport.h:340
void wait()
Wait on the condition variable.
Definition ThreadSupport.cc:306
Mutex _mutex
Definition ThreadSupport.h:371
Cond & operator=(const Cond &)
No assignment allowed.
Cond()
Construct a POSIX condition variable, with default attributes.
Definition ThreadSupport.cc:263
~Cond()
Destruct a Cond.
Definition ThreadSupport.cc:281
void signal()
Unblock at least one thread waiting on the condition variable.
Definition ThreadSupport.h:328
void unlock()
Unlock the mutex associated with the condition variable.
Definition ThreadSupport.h:315
Definition Exception.h:35
Definition ThreadSupport.h:549
void sync()
Definition ThreadSupport.cc:381
int debug
Definition ThreadSupport.h:561
Cond _co
Definition ThreadSupport.h:558
int _n
Definition ThreadSupport.h:559
int _count
Definition ThreadSupport.h:560
Multisync(int n)
Definition ThreadSupport.cc:370
void init()
Definition ThreadSupport.cc:399
A C++ wrapper for a POSIX mutex attributes.
Definition ThreadSupport.h:52
void setPShared(int val)
Set the mutex pshared attribute, one of PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED.
Definition ThreadSupport.cc:144
int getType() const
Definition ThreadSupport.cc:87
int getPShared() const
Definition ThreadSupport.cc:160
pthread_mutexattr_t _attrs
Definition ThreadSupport.h:118
void setType(int val)
Set the mutex type attribute, one of PTHREAD_MUTEX_NORMAL,PTHREAD_MUTEX_ERRORCHECK,...
Definition ThreadSupport.cc:71
pthread_mutexattr_t * ptr()
Definition ThreadSupport.h:113
MutexAttributes()
Create instance with default values, type = PTHREAD_MUTEX_DEFAULT, priority protocol=PTHREAD_PRIO_NON...
Definition ThreadSupport.cc:42
~MutexAttributes()
Definition ThreadSupport.cc:66
A C++ wrapper for a POSIX mutex.
Definition ThreadSupport.h:161
void lock()
Lock the Mutex.
Definition ThreadSupport.h:216
pthread_mutex_t _p_mutex
Definition ThreadSupport.h:248
Mutex(int type=PTHREAD_MUTEX_DEFAULT)
Construct a POSIX mutex of the given type.
Definition ThreadSupport.cc:212
MutexAttributes _attrs
Definition ThreadSupport.h:250
pthread_mutex_t * ptr()
Get the pointer to the pthread_mutex_t.
Definition ThreadSupport.cc:258
void unlock()
Unlock the Mutex.
Definition ThreadSupport.h:230
~Mutex()
Destruct a Mutex.
Definition ThreadSupport.cc:240
Mutex & operator=(const Mutex &)
No assignment allowed.
A C++ wrapper for a POSIX rwlock attributes.
Definition ThreadSupport.h:127
pthread_rwlockattr_t * ptr()
Definition ThreadSupport.h:149
void setPShared(int val)
Set the mutex pshared attribute, one of PTHREAD_PROCESS_PRIVATE or PTHREAD_PROCESS_SHARED.
Definition ThreadSupport.cc:189
~RWLockAttributes()
Definition ThreadSupport.cc:184
int getPShared() const
Definition ThreadSupport.cc:205
RWLockAttributes()
Definition ThreadSupport.cc:167
pthread_rwlockattr_t _attrs
Definition ThreadSupport.h:154
A C++ wrapper for a POSIX rwlock.
Definition ThreadSupport.h:379
void unlock()
Unlock the RWLock.
Definition ThreadSupport.h:437
RWLockAttributes _attrs
Definition ThreadSupport.h:457
~RWLock()
Destruct a RWLock.
Definition ThreadSupport.cc:349
RWLock & operator=(const RWLock &)
No assignment allowed.
void wrlock()
Acquire a write lock.
Definition ThreadSupport.h:424
void rdlock()
Acquire a read lock.
Definition ThreadSupport.h:411
RWLock()
Construct a POSIX rwlock.
Definition ThreadSupport.cc:320
pthread_rwlock_t _p_rwlock
Definition ThreadSupport.h:455
pthread_rwlock_t * ptr()
Get the pointer to the pthread_rwlock_t.
Definition ThreadSupport.cc:366
A POSIX semaphore.
Definition ThreadSupport.h:465
Semaphore & operator=(const Semaphore &)
No assignment allowed.
void wait()
Suspend calling thread until the semaphore has a non-zero count.
Definition ThreadSupport.h:489
int getValue()
Get the current value of the Semaphore.
Definition ThreadSupport.h:521
void post()
Atomically increment the Semaphore.
Definition ThreadSupport.h:507
sem_t _sem
Definition ThreadSupport.h:545
bool check()
Do a non-blocking wait on the Semaphore.
Definition ThreadSupport.h:499
sem_t * ptr()
Get the pointer to the semaphore (for legacy C code).
Definition ThreadSupport.h:531
Semaphore()
Constructor.
Definition ThreadSupport.h:471
Semaphore(const Semaphore &)
No copying.
~Semaphore()
Destructor.
Definition ThreadSupport.h:480
Synchronized is used a simple guard object for critical sections.
Definition ThreadSupport.h:575
Cond * condp
Definition ThreadSupport.h:610
Mutex * mutexp
Definition ThreadSupport.h:609
Synchronized(Mutex &mutex_)
Definition ThreadSupport.h:594
Synchronized & operator=(const Synchronized &)
~Synchronized()
On destruction, unlock the lock.
Definition ThreadSupport.h:602
Synchronized(Cond &cond_)
Construct the guard object and lock() the lock.
Definition ThreadSupport.h:586
Synchronized(const Synchronized &)
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31