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);
An optimized and convertable shared lock.
The conditional is a common base for other thread synchronizing classes.
T &() max(T &o1, T &o2)
Convenience function to return max of two objects.
void wait(void)
Wait (block) until signalled.
Barrier barrier_t
Convenience type for using thread barriers.
A portable implementation of "barrier" thread sychronization.
void unlock(void)
Unlock the conditional's supporting mutex.
static pthread_condattr_t * initializer(void)
Support function for getting conditional attributes for realtime scheduling.
void waitBroadcast(void)
Wait (block) until broadcast.
void waitSignal(void)
Wait (block) until signalled.
void lock(void)
Lock the conditional's supporting mutex.
Realtime timers and timer queues.
void unlock(void)
Unlock the conditional's supporting mutex.
ConditionalAccess accesslock_t
Convenience type for scheduling access.
void broadcast(void)
Signal the conditional to release all broadcast threads.
Condition Mutex to pair with conditionals.
Private heaps, pools, and associations.
void wait(void)
Wait (block) until signalled.
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.
The conditional rw seperates scheduling for optizming behavior or rw locks.
void broadcast(void)
Signal the conditional to release all waiting threads.
The condition Var allows multiple conditions to share a mutex.
void lock(void)
Lock the conditional's supporting mutex.
Common namespace for all ucommon objects.
static void set(struct timespec *hires, timeout_t timeout)
Convert a millisecond timeout into use for high resolution conditional timers.
An exclusive locking access interface base.
void signal(void)
Signal the conditional to release one signalled thread.
void signal(void)
Signal the conditional to release one waiting thread.
void operator++(void)
Convenience operator to wait on a counting semaphore.
Locking protocol classes for member function automatic operations.
void signal(void)
Signal the conditional to release one waiting thread.
Semaphore semaphore_t
Convenience type for using counting semaphores.
Common base class for all objects that can be formed into a linked list.
Event notification to manage scheduled realtime threads.
void operator--(void)
Convenience operator to release a counting semaphore.
void broadcast(void)
Signal the conditional to release all waiting threads.
A portable counting semaphore class.