Go to the documentation of this file.
34 #ifndef _UCOMMON_CONDITION_H_
35 #define _UCOMMON_CONDITION_H_
37 #ifndef _UCOMMON_CPR_H_
41 #ifndef _UCOMMON_ACCESS_H_
45 #ifndef _UCOMMON_TIMERS_H_
49 #ifndef _UCOMMON_MEMORY_H_
65 friend class autolock;
70 #if defined(_MSTHREADS_)
71 mutable CRITICAL_SECTION mutex;
73 mutable pthread_mutex_t mutex;
88 inline void lock(
void) {
89 EnterCriticalSection(&mutex);
92 inline void unlock(
void) {
93 LeaveCriticalSection(&mutex);
101 pthread_mutex_lock(&mutex);
108 pthread_mutex_unlock(&mutex);
112 class __EXPORT autolock
116 CRITICAL_SECTION *mutex;
118 pthread_mutex_t *mutex;
120 __DELETE_COPY(autolock);
124 mutex = &
object->mutex;
126 EnterCriticalSection(mutex);
128 pthread_mutex_lock(mutex);
134 LeaveCriticalSection(mutex);
136 pthread_mutex_unlock(mutex);
154 friend class ConditionList;
156 #if defined(_MSTHREADS_)
157 mutable CONDITION_VARIABLE cond;
159 mutable pthread_cond_t cond;
186 bool wait(
struct timespec *timeout);
191 void broadcast(
void);
198 pthread_cond_wait(&cond, &shared->mutex);
205 pthread_cond_signal(&cond);
212 pthread_cond_broadcast(&cond);
236 #if defined(_MSTHREADS_)
237 mutable CONDITION_VARIABLE cond;
240 class __LOCAL attribute
243 pthread_condattr_t attr;
247 __LOCAL
static attribute attr;
250 mutable pthread_cond_t cond;
267 bool wait(
struct timespec *timeout);
272 void broadcast(
void);
279 pthread_cond_wait(&cond, &mutex);
286 pthread_cond_signal(&cond);
293 pthread_cond_broadcast(&cond);
307 friend class autolock;
310 #if !defined(_MSTHREADS_) && !defined(__PTH__)
327 static void set(
struct timespec *hires, timeout_t timeout);
343 #if defined _MSTHREADS_
344 CONDITION_VARIABLE bcast;
346 mutable pthread_cond_t bcast;
349 static unsigned max_sharing;
351 unsigned pending, waiting, sharing;
388 inline static void set(
struct timespec *hires, timeout_t timeout) {
394 inline void lock(
void) {
395 EnterCriticalSection(&mutex);
398 inline void unlock(
void) {
399 LeaveCriticalSection(&mutex);
402 void waitSignal(
void);
404 void waitBroadcast(
void);
406 inline void signal(
void) {
410 inline void broadcast(
void) {
419 pthread_mutex_lock(&mutex);
426 pthread_mutex_unlock(&mutex);
433 pthread_cond_wait(&cond, &mutex);
440 pthread_cond_wait(&bcast, &mutex);
448 pthread_cond_signal(&cond);
455 pthread_cond_broadcast(&bcast);
517 __DELETE_COPY(Context);
529 virtual void _unshare(
void) __OVERRIDE;
531 Context *getContext(
void);
631 unsigned operator--(
void);
658 unsigned count, waits, used;
661 virtual void _unshare(
void) __OVERRIDE;
666 typedef autoshared<Semaphore> autosync;
void signal(void)
Signal the conditional to release one waiting thread.
Private heaps, pools, and associations.
ConditionMutex()
Initialize and construct conditional.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
Realtime timers and timer queues.
virtual void share(void)
Return an exclusive access lock back to share mode.
Conditional()
Initialize and construct conditional.
void access(void)
Acquire access (shared read) lock.
void modify(void)
Acquire write (exclusive modify) lock.
void unlock(void)
Unlock the conditional's supporting mutex.
void set(unsigned count)
Dynamically alter the number of threads required.
void modify(void)
Exclusive mode write thread scheduling.
bool wait(timeout_t timeout)
Wait until the semphore usage count is less than the thread limit.
The condition Var allows multiple conditions to share a mutex.
void signal(void)
Signal the conditional to release one signalled thread.
void wait(void)
Wait (block) until signalled.
Common namespace for all ucommon objects.
bool waitSignal(struct timespec *timeout)
Conditional wait for signal on timespec timeout.
bool wait(struct timespec *timeout)
Conditional wait for signal on timespec timeout.
ConditionVar(ConditionMutex *mutex)
Initialize and construct conditional.
~ConditionVar()
Destroy conditional, release any blocked threads.
void signal(void)
Signal the conditional to release one waiting thread.
virtual void exclusive(void)
Convert read lock into exclusive (write/modify) access.
void operator--(void)
Convenience operator to release a counting semaphore.
void set(unsigned count)
Alter semaphore limit at runtime.
void lock(void)
Lock the conditional's supporting mutex.
Event notification to manage scheduled realtime threads.
Barrier(unsigned count)
Construct a barrier with an initial size.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
~Conditional()
Destroy conditional, release any blocked threads.
void release(void)
Release access mode read scheduling.
void unlock(void)
Unlock the conditional's supporting mutex.
void release(void)
Release the semaphore after waiting for it.
bool wait(struct timespec *timeout)
Conditional wait for signal on timespec timeout.
An exclusive locking access interface base.
void wait(void)
Wait (block) until signalled.
Barrier barrier_t
Convenience type for using thread barriers.
void wait(void)
Wait at the barrier until the count of threads waiting is reached.
Locking protocol classes for member function automatic operations.
ConditionalLock()
Construct conditional lock for default concurrency.
void broadcast(void)
Signal the conditional to release all waiting threads.
unsigned operator++(void)
Alternative prefix form of the same increment operation.
virtual void _share(void)
Access interface to share lock the object.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
The conditional rw seperates scheduling for optizming behavior or rw locks.
~Barrier()
Destroy barrier and release pending threads.
bool wait(timeout_t timeout)
Wait at the barrier until either the count of threads waiting is reached or a timeout has occurred.
bool waitSignal(timeout_t timeout)
Conditional wait for signal on millisecond timeout.
Semaphore semaphore_t
Convenience type for using counting semaphores.
void dec(void)
Reduce the number of threads required.
ConditionalAccess()
Initialize and construct conditional.
bool wait(timeout_t timeout)
Conditional wait for signal on millisecond timeout.
static pthread_condattr_t * initializer(void)
Support function for getting conditional attributes for realtime scheduling.
void lock(void)
Lock the conditional's supporting mutex.
void broadcast(void)
Signal the conditional to release all waiting threads.
void wait(void)
Wait until the semphore usage count is less than the thread limit.
void waitBroadcast(void)
Wait (block) until broadcast.
virtual void _share(void)
Access interface to share lock the object.
bool wait(timeout_t timeout)
Conditional wait for signal on millisecond timeout.
void broadcast(void)
Signal the conditional to release all broadcast threads.
A portable counting semaphore class.
void access(void)
Access mode shared thread scheduling.
void operator++(void)
Convenience operator to wait on a counting semaphore.
~ConditionalAccess()
Destroy conditional, release any blocked threads.
ConditionalAccess accesslock_t
Convenience type for scheduling access.
Semaphore(unsigned count, unsigned avail)
Alternate onstructor with ability to preset available slots.
bool waitBroadcast(timeout_t timeout)
Conditional wait for broadcast on millisecond timeout.
void waitSignal(void)
Wait (block) until signalled.
void commit(void)
Commit changes / release a modify lock.
Common base class for all objects that can be formed into a linked list.
~ConditionalLock()
Destroy conditional lock.
void limit_sharing(unsigned max)
Specify a maximum sharing (access) limit.
Condition Mutex to pair with conditionals.
A portable implementation of "barrier" thread sychronization.
void release(void)
Release a shared lock.
void inc(void)
Dynamically increment the number of threads required.
Semaphore(unsigned count=0)
Construct a semaphore with an initial count of threads to permit.
ConditionalLock condlock_t
Convenience type for using conditional locks.
An optimized and convertable shared lock.
The conditional is a common base for other thread synchronizing classes.
~ConditionMutex()
Destroy conditional, release any blocked threads.
void commit(void)
Complete exclusive mode write scheduling.
bool waitBroadcast(struct timespec *timeout)
Conditional wait for broadcast on timespec timeout.