ucommon/thread.h File Reference

Thread classes and sychronization objects. More...

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

Namespaces

namespace  ucc
 

Common namespace for all ucommon objects.


Defines

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

Typedefs

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

Functions

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

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


Generated on 18 Dec 2009 for UCommon by  doxygen 1.6.1