ucommon

ucommon/thread.h File Reference

Thread classes and sychronization objects. More...

#include <ucommon/platform.h>
#include <ucommon/access.h>
#include <ucommon/timers.h>
#include <ucommon/memory.h>
Include dependency graph for thread.h:

Go to the source code of this file.

Data Structures

class  auto_protect
 A mutex locked object smart pointer helper class. More...
class  barrier
 A portable implimentation of "barrier" thread sychronization. More...
class  Conditional
 The conditional is a common base for other thread synchronizing classes. More...
class  ConditionalAccess
 The conditional rw seperates scheduling for optizming behavior or rw locks. More...
class  ConditionalLock
 An optimized and convertable shared lock. More...
class  DetachedThread
 A detached thread object that is stand-alone. More...
class  JoinableThread
 A child thread object that may be joined by parent. More...
class  locked_instance< T >
 A templated smart pointer instance for lock protected objects. More...
class  locked_pointer< T >
 Templated locked pointer for referencing locked objects of specific type. More...
class  locked_release
 Auto-pointer support class for locked objects. More...
class  LockedPointer
 An object pointer that uses mutex to assure thread-safe singleton use. More...
class  mutex
 Generic non-recursive exclusive lock class. More...
class  mutex::gaurd
 Gaurd class to apply scope based mutex locking to objects. More...
class  mutex_pointer< T >
 Typed smart locked pointer class. More...
class  ReusableAllocator
 Class for resource bound memory pools between threads. More...
class  rexlock
 Portable recursive exclusive lock. More...
class  rwlock
 A generic and portable implimentation of Read/Write locking. More...
class  rwlock::gaurd_reader
 Gaurd class to apply scope based access locking to objects. More...
class  rwlock::gaurd_writer
 Gaurd class to apply scope based exclusive locking to objects. More...
class  semaphore
 A portable counting semaphore class. More...
class  shared_instance< T >
 A templated smart pointer instance for shared singleton typed objects. More...
class  shared_pointer< T >
 Templated shared pointer for singleton shared objects of specific type. More...
class  shared_release
 Auto-pointer support class for shared singleton objects. More...
class  SharedObject
 Shared singleton object. More...
class  SharedPointer
 The shared pointer is used to manage a singleton instance of shared object. More...
class  Thread
 An abstract class for defining classes that operate as a thread. More...
class  TimedEvent
 Event notification to manage scheduled realtime threads. More...

Defines

#define ENTER_EXCLUSIVE
#define LEAVE_EXCLUSIVE   pthread_mutex_unlock(&__sync__);} while(0);

Typedefs

typedef ConditionalAccess accesslock_t
 Convenience type for scheduling access.
typedef barrier barrier_t
 Convenience type for using thread barriers.
typedef ConditionalLock condlock_t
 Convenience type for using conditional locks.
typedef mutex Mutex
 Convenience type for using exclusive mutex on systems which define "mutex" (solaris) already to avoid type confusion.
typedef mutex mutex_t
 Convenience type for using exclusive mutex locks.
typedef rexlock rexlock_t
 Convenience type for using recursive exclusive locks.
typedef rwlock rwlock_t
 Convenience type for using read/write locks.
typedef semaphore semaphore_t
 Convenience type for using counting semaphores.
typedef TimedEvent timedevent_t
 Convenience type for using timed events.

Functions

void access (accesslock_t &lock)
 Convenience function to shared read schedule conditional access.
void access (condlock_t &lock)
 Convenience function for shared access to a conditional lock.
void acquire (mutex_t &mutex)
 Convenience function to acquire a mutex.
void commit (accesslock_t &lock)
 Convenience function to commit an exclusive access lock.
void commit (condlock_t &lock)
 Convenience function to commit and release an exclusively locked conditional lock.
bool exclusive (rwlock_t &lock, timeout_t timeout=Timer::inf)
 Convenience function for exclusive write access to a read/write lock.
void exclusive (condlock_t &lock)
 Convenience function to exclusively lock shared conditional lock.
void lock (rexlock_t &lock)
 Convenience function to lock a shared recursive mutex lock.
void modify (accesslock_t &lock)
 Convenience function to exclusively schedule conditional access.
void modify (condlock_t &lock)
 Convenience function to exclusively aquire a conditional lock.
void release (condlock_t &lock)
 Convenience function to release shared access to a conditional lock.
void release (rexlock_t &lock)
 Convenience function to release a shared recursive mutex lock.
void release (rwlock_t &lock)
 Convenience function to release a shared lock.
void release (accesslock_t &lock)
 Convenience function to release an access lock.
void release (semaphore_t &semaphore)
 Convenience function to release a semaphore.
void release (mutex_t &mutex)
 Convenience function to release a mutex.
bool share (rwlock_t &lock, timeout_t timeout=Timer::inf)
 Convenience function for shared read access to a read/write lock.
void share (condlock_t &lock)
 Convenience function to restore shared access on a conditional lock.
void start (JoinableThread *thread, int priority=0)
 Convenience function to start a joinable thread.
void start (DetachedThread *thread, int priority=0)
 Convenience function to start a detached thread.
void wait (semaphore_t &semaphore, timeout_t timeout=Timer::inf)
 Convenience function to wait on a semaphore.
void wait (barrier_t &barrier)
 Convenience function to wait on a barrier.

Detailed Description

Thread classes and sychronization objects.

The theory behind ucommon thread classes is that they would be used to create derived classes where thread-specific data can be stored as member data of the derived class. The run method is called when the context is executed. Since we use a pthread foundation, we support both detached threads and joinable threads. Objects based on detached threads should be created with new, and will automatically delete when the thread context exits. Joinable threads will be joined with deleted.

The theory behind ucommon sychronization objects is that all upper level sychronization objects can be formed directly from a mutex and conditional. This includes semaphores, barriers, rwlock, our own specialized conditional lock, resource-bound locking, and recurive exclusive locks. Using only conditionals means we are not dependent on platform specific pthread implimentations that may not impliment some of these, and hence improves portability and consistency. Given that our rwlocks are recursive access locks, one can safely create read/write threading pairs where the read threads need not worry about deadlocks and the writers need not either if they only write-lock one instance at a time to change state.

Definition in file thread.h.


Define Documentation

#define ENTER_EXCLUSIVE
Value:
do { static pthread_mutex_t __sync__ = PTHREAD_MUTEX_INITIALIZER; \
        pthread_mutex_lock(&__sync__);

Definition at line 2227 of file thread.h.


Function Documentation

void access ( accesslock_t lock) [inline]

Convenience function to shared read schedule conditional access.

Parameters:
lockto access shared.

Definition at line 2127 of file thread.h.

Here is the call graph for this function:

void access ( condlock_t lock) [inline]

Convenience function for shared access to a conditional lock.

Parameters:
lockto access.

Definition at line 2178 of file thread.h.

Here is the call graph for this function:

void acquire ( mutex_t mutex) [inline]

Convenience function to acquire a mutex.

Parameters:
mutexto acquire.

Definition at line 2106 of file thread.h.

Here is the call graph for this function:

void commit ( accesslock_t lock) [inline]

Convenience function to commit an exclusive access lock.

lock.

Parameters:
lockto commit.

Definition at line 2142 of file thread.h.

Here is the call graph for this function:

void commit ( condlock_t lock) [inline]

Convenience function to commit and release an exclusively locked conditional lock.

Parameters:
lockto commit.

Definition at line 2171 of file thread.h.

Here is the call graph for this function:

bool exclusive ( rwlock_t lock,
timeout_t  timeout = Timer::inf 
) [inline]

Convenience function for exclusive write access to a read/write lock.

Parameters:
lockto write lock.
timeoutto wait for exclusive locking.

Definition at line 2193 of file thread.h.

Here is the call graph for this function:

void exclusive ( condlock_t lock) [inline]

Convenience function to exclusively lock shared conditional lock.

Parameters:
lockto make exclusive.

Definition at line 2149 of file thread.h.

Here is the call graph for this function:

void lock ( rexlock_t lock) [inline]

Convenience function to lock a shared recursive mutex lock.

Parameters:
lockto acquire.

Definition at line 2215 of file thread.h.

Here is the call graph for this function:

void modify ( accesslock_t lock) [inline]

Convenience function to exclusively schedule conditional access.

Parameters:
lockto make exclusive.

Definition at line 2120 of file thread.h.

Here is the call graph for this function:

void modify ( condlock_t lock) [inline]

Convenience function to exclusively aquire a conditional lock.

Parameters:
lockto acquire for modify.

Definition at line 2163 of file thread.h.

Here is the call graph for this function:

void release ( condlock_t lock) [inline]

Convenience function to release shared access to a conditional lock.

Parameters:
lockto release.

Definition at line 2185 of file thread.h.

Here is the call graph for this function:

void release ( rexlock_t lock) [inline]

Convenience function to release a shared recursive mutex lock.

Parameters:
lockto release.

Definition at line 2222 of file thread.h.

Here is the call graph for this function:

void release ( rwlock_t lock) [inline]

Convenience function to release a shared lock.

Parameters:
lockto release.

Definition at line 2208 of file thread.h.

Here is the call graph for this function:

void release ( accesslock_t lock) [inline]

Convenience function to release an access lock.

Parameters:
lockto release.

Definition at line 2134 of file thread.h.

Here is the call graph for this function:

void release ( semaphore_t semaphore) [inline]

Convenience function to release a semaphore.

Parameters:
semaphoreto release.

Definition at line 2099 of file thread.h.

Here is the call graph for this function:

void release ( mutex_t mutex) [inline]

Convenience function to release a mutex.

Parameters:
mutexto release.

Definition at line 2113 of file thread.h.

Here is the call graph for this function:

bool share ( rwlock_t lock,
timeout_t  timeout = Timer::inf 
) [inline]

Convenience function for shared read access to a read/write lock.

Parameters:
lockto share read lock.
timeoutto wait for shared access.

Definition at line 2201 of file thread.h.

Here is the call graph for this function:

void share ( condlock_t lock) [inline]

Convenience function to restore shared access on a conditional lock.

Parameters:
lockto make shared.

Definition at line 2156 of file thread.h.

Here is the call graph for this function:

void start ( JoinableThread thread,
int  priority = 0 
) [inline]

Convenience function to start a joinable thread.

Parameters:
threadto start.
priorityof thread.
Examples:
thread.cpp.

Definition at line 2023 of file thread.h.

Here is the call graph for this function:

void start ( DetachedThread thread,
int  priority = 0 
) [inline]

Convenience function to start a detached thread.

Parameters:
threadto start.
priorityof thread.

Definition at line 2031 of file thread.h.

Here is the call graph for this function:

void wait ( semaphore_t semaphore,
timeout_t  timeout = Timer::inf 
) [inline]

Convenience function to wait on a semaphore.

Parameters:
semaphoreto wait on.
timeoutto wait for.

Definition at line 2092 of file thread.h.

Here is the call graph for this function:

void wait ( barrier_t barrier) [inline]

Convenience function to wait on a barrier.

Parameters:
barrierto wait.

Definition at line 2084 of file thread.h.

Here is the call graph for this function: