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;
179 bool wait(timeout_t timeout);
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;
260 bool wait(timeout_t timeout);
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;
358 bool waitSignal(timeout_t timeout);
365 bool waitBroadcast(timeout_t timeout);
373 bool waitSignal(
struct timespec *timeout);
380 bool waitBroadcast(
struct timespec *timeout);
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);
495 void limit_sharing(
unsigned max);
517 __DELETE_COPY(Context);
528 virtual void _share(
void) __OVERRIDE;
529 virtual void _unshare(
void) __OVERRIDE;
531 Context *getContext(
void);
568 virtual void exclusive(
void);
573 virtual void share(
void);
613 void set(
unsigned count);
629 unsigned operator++(
void);
631 unsigned operator--(
void);
644 bool wait(timeout_t timeout);
658 unsigned count, waits, used;
660 virtual void _share(
void) __OVERRIDE;
661 virtual void _unshare(
void) __OVERRIDE;
666 typedef autoshared<Semaphore> autosync;
679 Semaphore(
unsigned count,
unsigned avail);
694 bool wait(timeout_t timeout);
700 void set(
unsigned count);
Condition Mutex to pair with conditionals.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
Event notification to manage scheduled realtime threads.
The conditional rw seperates scheduling for optizming behavior or rw locks.
void broadcast(void)
Signal the conditional to release all waiting threads.
Common namespace for all ucommon objects.
A portable counting semaphore class.
void unlock(void)
Unlock the conditional's supporting mutex.
void broadcast(void)
Signal the conditional to release all waiting threads.
void operator--(void)
Convenience operator to release a counting semaphore.
void signal(void)
Signal the conditional to release one signalled thread.
void lock(void)
Lock the conditional's supporting mutex.
An optimized and convertable shared lock.
The conditional is a common base for other thread synchronizing classes.
Private heaps, pools, and associations.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
ConditionalLock condlock_t
Convenience type for using conditional locks.
Realtime timers and timer queues.
void signal(void)
Signal the conditional to release one waiting thread.
void wait(void)
Wait (block) until signalled.
Barrier barrier_t
Convenience type for using thread barriers.
Semaphore semaphore_t
Convenience type for using counting semaphores.
void waitSignal(void)
Wait (block) until signalled.
void unlock(void)
Unlock the conditional's supporting mutex.
void operator++(void)
Convenience operator to wait on a counting semaphore.
void broadcast(void)
Signal the conditional to release all broadcast threads.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
Common base class for all objects that can be formed into a linked list.
The condition Var allows multiple conditions to share a mutex.
Locking protocol classes for member function automatic operations.
void waitBroadcast(void)
Wait (block) until broadcast.
ConditionalAccess accesslock_t
Convenience type for scheduling access.
void signal(void)
Signal the conditional to release one waiting thread.
A portable implementation of "barrier" thread sychronization.
An exclusive locking access interface base.
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 wait(void)
Wait (block) until signalled.