Thread classes and sychronization objects. More...
#include <ucommon/cpr.h>
#include <ucommon/access.h>
#include <ucommon/timers.h>
#include <ucommon/memory.h>
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::guard |
Guard 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::guard_reader |
Guard class to apply scope based access locking to objects. More... | |
class | ucommon::ThreadLock::guard_writer |
Guard 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 | EXCLUSIVE(obj) for(bool _sync_flag_ = _rw_writer_(obj); _sync_flag_; _sync_flag_ = _rw_release_(obj)) |
#define | LEAVE_EXCLUSIVE pthread_mutex_unlock(&__sync__);} while(0); |
#define | SHARED(obj) for(bool _sync_flag_ = _rw_reader_(obj); _sync_flag_; _sync_flag_ = _rw_release_(obj)) |
#define | SYNC(obj) for(bool _sync_flag_ = _sync_protect_(obj); _sync_flag_; _sync_flag_ = _sync_release_(obj)) |
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 | |
bool | ucommon::_rw_reader_ (const void *obj) |
bool | ucommon::_rw_release_ (const void *obj) |
bool | ucommon::_rw_writer_ (const void *obj) |
bool | ucommon::_sync_protect_ (const void *obj) |
bool | ucommon::_sync_release_ (const void *obj) |
void | ucommon::access (condlock_t &lock) |
Convenience function for shared access to a conditional lock. | |
void | ucommon::access (accesslock_t &lock) |
Convenience function to shared read schedule conditional access. | |
void | ucommon::acquire (mutex_t &mutex) |
Convenience function to acquire a mutex. | |
void | ucommon::commit (condlock_t &lock) |
Convenience function to commit and release an exclusively locked conditional lock. | |
void | ucommon::commit (accesslock_t &lock) |
Convenience function to commit an exclusive access 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::exclusive (condlock_t &lock) |
Convenience function to exclusively lock shared conditional lock. | |
void | ucommon::lock (rexlock_t &lock) |
Convenience function to lock a shared recursive mutex lock. | |
void | ucommon::modify (condlock_t &lock) |
Convenience function to exclusively aquire a conditional lock. | |
void | ucommon::modify (accesslock_t &lock) |
Convenience function to exclusively schedule conditional access. | |
void | ucommon::release (rexlock_t &lock) |
Convenience function to release a shared recursive mutex lock. | |
void | ucommon::release (rwlock_t &lock) |
Convenience function to release a shared lock. | |
void | ucommon::release (condlock_t &lock) |
Convenience function to release shared access to a conditional lock. | |
void | ucommon::release (accesslock_t &lock) |
Convenience function to release an access lock. | |
void | ucommon::release (mutex_t &mutex) |
Convenience function to release a mutex. | |
void | ucommon::release (semaphore_t &semaphore) |
Convenience function to release a semaphore. | |
bool | ucommon::share (rwlock_t &lock, timeout_t timeout=Timer::inf) |
Convenience function for shared read access to a read/write lock. | |
void | ucommon::share (condlock_t &lock) |
Convenience function to restore shared access on a conditional lock. | |
void | ucommon::start (DetachedThread *thread, int priority=0) |
Convenience function to start a detached thread. | |
void | ucommon::start (JoinableThread *thread, int priority=0) |
Convenience function to start a joinable thread. | |
void | ucommon::wait (semaphore_t &semaphore, timeout_t timeout=Timer::inf) |
Convenience function to wait on a semaphore. | |
void | ucommon::wait (barrier_t &barrier) |
Convenience function to wait on a barrier. |
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.