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) {
389 Conditional::set(hires, 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) {
407 Conditional::signal();
410 inline void broadcast(
void) {
411 Conditional::broadcast();
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;
Private heaps, pools, and associations.
Locking protocol classes for member function automatic operations.
Realtime timers and timer queues.
Common namespace for all ucommon objects.
ConditionalAccess accesslock_t
Convenience type for scheduling access.
Semaphore semaphore_t
Convenience type for using counting semaphores.
ConditionalLock condlock_t
Convenience type for using conditional locks.
Barrier barrier_t
Convenience type for using thread barriers.
An exclusive locking access interface base.
Condition Mutex to pair with conditionals.
void unlock(void)
Unlock the conditional's supporting mutex.
void lock(void)
Lock the conditional's supporting mutex.
ConditionMutex()
Initialize and construct conditional.
~ConditionMutex()
Destroy conditional, release any blocked threads.
The condition Var allows multiple conditions to share a mutex.
bool wait(struct timespec *timeout)
Conditional wait for signal on timespec timeout.
ConditionVar(ConditionMutex *mutex)
Initialize and construct conditional.
void broadcast(void)
Signal the conditional to release all waiting threads.
void wait(void)
Wait (block) until signalled.
bool wait(timeout_t timeout)
Conditional wait for signal on millisecond timeout.
void signal(void)
Signal the conditional to release one waiting thread.
~ConditionVar()
Destroy conditional, release any blocked threads.
The conditional is a common base for other thread synchronizing classes.
static pthread_condattr_t * initializer(void)
Support function for getting conditional attributes for realtime scheduling.
void wait(void)
Wait (block) until signalled.
Conditional()
Initialize and construct conditional.
bool wait(struct timespec *timeout)
Conditional wait for signal on timespec timeout.
bool wait(timeout_t timeout)
Conditional wait for signal on millisecond timeout.
void broadcast(void)
Signal the conditional to release all waiting threads.
~Conditional()
Destroy conditional, release any blocked threads.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
void signal(void)
Signal the conditional to release one waiting thread.
The conditional rw seperates scheduling for optizming behavior or rw locks.
void access(void)
Access mode shared thread scheduling.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
void broadcast(void)
Signal the conditional to release all broadcast threads.
void release(void)
Release access mode read scheduling.
bool waitSignal(struct timespec *timeout)
Conditional wait for signal on timespec timeout.
void unlock(void)
Unlock the conditional's supporting mutex.
bool waitSignal(timeout_t timeout)
Conditional wait for signal on millisecond timeout.
void modify(void)
Exclusive mode write thread scheduling.
void commit(void)
Complete exclusive mode write scheduling.
void waitBroadcast(void)
Wait (block) until broadcast.
void limit_sharing(unsigned max)
Specify a maximum sharing (access) limit.
~ConditionalAccess()
Destroy conditional, release any blocked threads.
ConditionalAccess()
Initialize and construct conditional.
void lock(void)
Lock the conditional's supporting mutex.
bool waitBroadcast(struct timespec *timeout)
Conditional wait for broadcast on timespec timeout.
void waitSignal(void)
Wait (block) until signalled.
void signal(void)
Signal the conditional to release one signalled thread.
bool waitBroadcast(timeout_t timeout)
Conditional wait for broadcast on millisecond timeout.
An optimized and convertable shared lock.
~ConditionalLock()
Destroy conditional lock.
void modify(void)
Acquire write (exclusive modify) lock.
virtual void exclusive(void)
Convert read lock into exclusive (write/modify) access.
void access(void)
Acquire access (shared read) lock.
void commit(void)
Commit changes / release a modify lock.
virtual void _share(void)
Access interface to share lock the object.
ConditionalLock()
Construct conditional lock for default concurrency.
virtual void share(void)
Return an exclusive access lock back to share mode.
void release(void)
Release a shared lock.
A portable implementation of "barrier" thread sychronization.
void inc(void)
Dynamically increment the number of threads required.
~Barrier()
Destroy barrier and release pending threads.
unsigned operator++(void)
Alternative prefix form of the same increment operation.
void wait(void)
Wait at the barrier until the count of threads waiting is reached.
bool wait(timeout_t timeout)
Wait at the barrier until either the count of threads waiting is reached or a timeout has occurred.
Barrier(unsigned count)
Construct a barrier with an initial size.
void set(unsigned count)
Dynamically alter the number of threads required.
void dec(void)
Reduce the number of threads required.
A portable counting semaphore class.
bool wait(timeout_t timeout)
Wait until the semphore usage count is less than the thread limit.
void operator--(void)
Convenience operator to release a counting semaphore.
void operator++(void)
Convenience operator to wait on a counting semaphore.
virtual void _share(void)
Access interface to share lock the object.
Semaphore(unsigned count, unsigned avail)
Alternate onstructor with ability to preset available slots.
void release(void)
Release the semaphore after waiting for it.
Semaphore(unsigned count=0)
Construct a semaphore with an initial count of threads to permit.
void wait(void)
Wait until the semphore usage count is less than the thread limit.
void set(unsigned count)
Alter semaphore limit at runtime.
Common base class for all objects that can be formed into a linked list.
Event notification to manage scheduled realtime threads.