43 #ifndef _UCOMMON_THREAD_H_ 44 #define _UCOMMON_THREAD_H_ 46 #ifndef _UCOMMON_CPR_H_ 50 #ifndef _UCOMMON_ACCESS_H_ 54 #ifndef _UCOMMON_TIMERS_H_ 58 #ifndef _UCOMMON_MEMORY_H_ 62 #ifndef _UCOMMON_CONDITION_H_ 92 virtual void _share(
void) __OVERRIDE;
94 virtual void _lock(
void) __OVERRIDE;
96 virtual void _unlock(
void) __OVERRIDE;
98 virtual void _unshare(
void) __OVERRIDE;
101 typedef autoshared<RWLock> autoreader;
103 typedef autoexclusive<RWLock> autowriter;
130 reader(
const void *
object);
142 void set(
const void *
object);
165 static bool lock(
const void *
object, timeout_t timeout = Timer::inf);
193 writer(
const void *
object);
205 void set(
const void *
object);
228 static bool lock(
const void *
object, timeout_t timeout = Timer::inf);
241 bool modify(timeout_t timeout = Timer::inf);
248 bool access(timeout_t timeout = Timer::inf);
256 static void indexing(
unsigned size);
262 static bool release(
const void *
object);
284 mutable pthread_cond_t cond;
287 mutable pthread_mutex_t mutex;
349 bool wait(timeout_t timeout);
379 virtual void _lock(
void) __OVERRIDE;
380 virtual void _unlock(
void) __OVERRIDE;
383 typedef autoexclusive<RecursiveMutex> autolock;
398 bool lock(timeout_t timeout);
462 __DELETE_COPY(
Mutex);
465 mutable pthread_mutex_t mlock;
467 virtual void _lock(
void) __OVERRIDE;
468 virtual void _unlock(
void) __OVERRIDE;
471 typedef autoexclusive<Mutex> autolock;
487 pthread_mutex_lock(&mlock);
494 pthread_mutex_lock(&mlock);
501 pthread_mutex_unlock(&mlock);
508 pthread_mutex_unlock(&mlock);
515 inline static void acquire(pthread_mutex_t *lock) {
516 pthread_mutex_lock(lock);
523 inline static void release(pthread_mutex_t *lock) {
524 pthread_mutex_unlock(lock);
533 static void indexing(
unsigned size);
540 static bool protect(
const void *
pointer);
546 static bool release(
const void *
pointer);
576 void set(
const void *
object);
595 inline operator bool()
const {
596 return object != NULL;
599 inline bool operator!()
const {
600 return object == NULL;
610 inline autoprotect(
const T *
object) : AutoProtect(object) {};
612 inline void set(
const T *
object) {
616 inline void release() {
620 inline autoprotect& operator=(
const T*
object) {
625 inline T* operator->()
const {
626 return static_cast<T*>(
object);
629 inline T& operator*()
const {
630 __THROW_DEREF(
object);
631 return *(static_cast<T*>(
object));
658 enum {R_UNUSED} reserved;
679 virtual bool is_active(
void)
const;
690 __DELETE_COPY(Local);
695 virtual void release(
void *instance) = 0;
697 virtual void *allocate();
704 void set(
void *instance);
708 inline void clear() {
719 void setPriority(
void);
725 static void yield(
void);
731 static void sleep(timeout_t timeout);
744 virtual void run(
void) = 0;
759 virtual void exit(
void);
764 static void init(
void);
769 static size_t cache(
void);
776 static void policy(
int polid);
782 static void concurrency(
int level);
790 static bool equal(pthread_t thread1, pthread_t thread2);
796 static pthread_t
self(void);
798 inline operator bool()
const {
802 inline bool operator!()
const {
806 inline bool isRunning(
void)
const {
810 static void release(
void);
832 volatile bool running;
834 volatile bool joining;
855 bool is_active(
void)
const __OVERRIDE;
857 virtual void run(
void) __OVERRIDE = 0;
869 void start(
int priority = 0);
916 void exit(
void) __OVERRIDE;
918 bool is_active(
void)
const __OVERRIDE;
920 virtual void run(
void) __OVERRIDE = 0;
929 void start(
int priority = 0);
952 #define __AUTOLOCK(x) autolock __autolock__(x) 953 #define __AUTOPROTECT(x) AutoProtect __autolock__(x) 954 #define __SYNC(x) for(bool _sync_flag_ = Mutex::protect(x); _sync_flag_; _sync_flag_ = !Mutex::release(x)) RWLock rwlock_t
Convenience type for using read/write locks.
The conditional is a common base for other thread synchronizing classes.
Class for resource bound memory pools between threads.
Apply automatic scope based exclusive locking to objects.
void operator=(const void *pointer)
Set guard to read lock a new object.
void unlock(void)
Release acquired lock.
Timer class to use when scheduling realtime events.
An exclusive locking protocol interface base.
Guard class to apply scope based mutex locking to objects.
void lock(void)
Acquire mutex lock.
T * init(T *memory)
Template function to initialize memory by invoking default constructor.
A detached thread object that is stand-alone.
RecursiveMutex rexlock_t
Convenience type for using recursive exclusive locks.
Realtime timers and timer queues.
A generic and portable implementation of Read/Write locking.
static void acquire(pthread_mutex_t *lock)
Convenience function to acquire os native mutex lock directly.
void background(void)
Start execution of child context as background thread.
void release(void)
Release acquired lock.
void acquire(void)
Acquire mutex lock.
Mutex mutex_t
Convenience type for using exclusive mutex locks.
Private heaps, pools, and associations.
Reusable objects for forming private heaps.
The conditional rw seperates scheduling for optizming behavior or rw locks.
Portable recursive exclusive lock.
ReusableObject * getNext(void)
Get next effective reusable object when iterating.
Apply automatic scope based access locking to objects.
void release(void)
Prematurely release a guard.
Common namespace for all ucommon objects.
An exclusive locking access interface base.
static void release(pthread_mutex_t *lock)
Convenience function to release os native mutex lock directly.
An abstract class for defining classes that operate as a thread.
Condition classes for thread sychronization and timing.
Generic non-recursive exclusive lock class.
Locking protocol classes for member function automatic operations.
void operator=(const void *pointer)
Set guard to read lock a new object.
A child thread object that may be joined by parent.
TimedEvent timedevent_t
Convenience type for using timed events.
Common base class for all objects that can be formed into a linked list.
Event notification to manage scheduled realtime threads.
Generic smart pointer class.
ReusableObject * next(ReusableObject *object)
Get next reusable object in the pool.
void set(const void *object)
Set guard to mutex lock a new object.