UCommon
Data Structures | Namespaces | Defines | Typedefs | Functions
ucommon/thread.h File Reference

Thread classes and sychronization objects. More...

#include <ucommon/cpr.h>
#include <ucommon/access.h>
#include <ucommon/timers.h>
#include <ucommon/memory.h>
Include dependency graph for thread.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

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

Namespaces

namespace  ucommon
 

Common namespace for all ucommon objects.


Defines

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

Typedefs

typedef ConditionalAccess ucommon::accesslock_t
 Convenience type for scheduling access.
typedef barrier ucommon::barrier_t
 Convenience type for using thread barriers.
typedef ConditionalLock ucommon::condlock_t
 Convenience type for using conditional locks.
typedef Mutex ucommon::mutex_t
 Convenience type for using exclusive mutex locks.
typedef RecursiveMutex ucommon::rexlock_t
 Convenience type for using recursive exclusive locks.
typedef ThreadLock ucommon::rwlock_t
 Convenience type for using read/write locks.
typedef Semaphore ucommon::semaphore_t
 Convenience type for using counting semaphores.
typedef TimedEvent ucommon::timedevent_t
 Convenience type for using timed events.

Functions

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

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 2248 of file thread.h.