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