Home | C-Bits Package Documentation | Project Page |
#include <ResourceLock_PTHREAD.h>
Inheritance diagram for cbits::ResourceLock_PTHREAD:
Public Types | |
enum | LockType { NONE = -1, READ = +1, WRITE = +2 } |
Lock types and states. More... | |
Public Methods | |
ResourceLock_PTHREAD () | |
virtual | ~ResourceLock_PTHREAD () |
const bool | lock (const LockType) |
Lock the resource. More... | |
const bool | unlock () |
Release the resource. More... | |
const bool | isLocked () const |
Test if the resource is locked (READ or WRITE). More... | |
const bool | isOwner (const bool lockit=true) const |
Test if this thread owns a lock on the resource. More... | |
const LockType | getLockType () const |
Determine the type of resource lock owned by this thread, if any. More... | |
Static Public Methods | |
ResourceLock * | create () |
Create a resource lock. More... | |
Protected Methods | |
virtual const bool | impl_lock_obj () const |
EMPTY *. More... | |
virtual const bool | impl_unlock_obj () const |
Release the internal lock after the object's state has stablized. More... | |
virtual const long | impl_get_threadid () const |
Get platform-specific thread ID. More... | |
virtual const bool | impl_wait_for_event () |
Wait for an event that indicates that another attempt can be made to lock the resource. More... | |
virtual const bool | impl_send_event () |
Emit an event that indicates that the oldes queued thread waiting for the resource can attempt to lock it. More... | |
Protected Attributes | |
std::list< long > | _queue |
|
Lock types and states.
|
|
|
|
|
|
Create a resource lock.
|
|
Determine the type of resource lock owned by this thread, if any.
|
|
Get platform-specific thread ID.
Implements cbits::ResourceLock. |
|
EMPTY *.
Implements cbits::ResourceLock. |
|
Emit an event that indicates that the oldes queued thread waiting for the resource can attempt to lock it.
Implements cbits::ResourceLock. |
|
Release the internal lock after the object's state has stablized.
Implements cbits::ResourceLock. |
|
Wait for an event that indicates that another attempt can be made to lock the resource.
Implements cbits::ResourceLock. |
|
Test if the resource is locked (READ or WRITE).
|
|
Test if this thread owns a lock on the resource.
|
|
Lock the resource. Any number of READ locks can be acquired on a resource that is not WRITE locked. If a READ lock is requested on a resource that is WRITE locked, this method will block until the WRITE lock is released. A WRITE lock can only be acquired on a resource that has no locks of any kind in effect. If a WRITE lock is requested on a resource that has either an existing WRITE lock or one or more READ locks, then this method will block until all locks have been released. If a lock can not be acquired on the resource due to one of the aforementioned conditions, the lock request is queued in a FIFO (and the method will block). Queued lock requests are handled in the order that they are placed on the queue. A WRITE lock request can not be 'starved' by multiple threads continually requesting READ locks on the resource. For example: If a thread requests a WRITE lock on a resource that has one or more READ locks in effect, the WRITE lock request will be queued as described above. If another thread then requests a READ lock on the same resource, before the WRITE lock request is effected, the READ lock request will also be queued even though only READ locks are in effect on the resource at the time. A lock request on a resource that is already owned by the thread is ignored even if the currently held lock is of a different type than the requested lock.
|
|
Release the resource. If one or more lock requests are pending, the oldest one is serviced.
|
|
|
|
|