Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cbits::ResourceLock_WIN32 Class Reference

Win32 implementation of the ResourceLock class. More...

#include <ResourceLock_WIN32.h>

Inheritance diagram for cbits::ResourceLock_WIN32:

[legend]
Collaboration diagram for cbits::ResourceLock_WIN32:
[legend]
List of all members.

Public Types

enum  LockType { NONE = -1, READ = +1, WRITE = +2 }
 Lock types and states. More...


Public Methods

 ResourceLock_WIN32 ()
virtual ~ResourceLock_WIN32 ()
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

ResourceLockcreate ()
 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

Detailed Description

Win32 implementation of the ResourceLock class.


Member Enumeration Documentation

enum cbits::ResourceLock::LockType [inherited]
 

Lock types and states.

Enumeration values:
NONE  No lock in effect.
READ  Read lock.
WRITE  Write lock.


Constructor & Destructor Documentation

ResourceLock_WIN32::ResourceLock_WIN32  
 

ResourceLock_WIN32::~ResourceLock_WIN32   [virtual]
 


Member Function Documentation

ResourceLock * ResourceLock::create   [static, inherited]
 

Create a resource lock.

Returns:
pointer to new ResourceLock instance.

const ResourceLock::LockType ResourceLock::getLockType   const [inherited]
 

Determine the type of resource lock owned by this thread, if any.

Returns:
an element of LockType corresponding to the type of lock owned by this thread. If the thread does not own a lock on the resource, a LockType of NONE is returned.

const long ResourceLock_WIN32::impl_get_threadid   const [protected, virtual]
 

Get platform-specific thread ID.

Returns:
a long value representing this threads ID.

Implements cbits::ResourceLock.

const bool ResourceLock_WIN32::impl_lock_obj   const [protected, virtual]
 

EMPTY *.

Implements cbits::ResourceLock.

const bool ResourceLock_WIN32::impl_send_event   [protected, virtual]
 

Emit an event that indicates that the oldes queued thread waiting for the resource can attempt to lock it.

Returns:
true if the thread should try again to lock the resource; false if an error occurred.

Implements cbits::ResourceLock.

const bool ResourceLock_WIN32::impl_unlock_obj   const [protected, virtual]
 

Release the internal lock after the object's state has stablized.

Returns:
true if the lock was successfully released; otherwise, false.

Implements cbits::ResourceLock.

const bool ResourceLock_WIN32::impl_wait_for_event   [protected, virtual]
 

Wait for an event that indicates that another attempt can be made to lock the resource.

Returns:
true if the thread should try again to lock the resource; false if an error occurred.

Implements cbits::ResourceLock.

const bool ResourceLock::isLocked   const [inherited]
 

Test if the resource is locked (READ or WRITE).

Returns:
true if the resource has at least one lock in effect.

const bool ResourceLock::isOwner const bool    lockit = true const [inherited]
 

Test if this thread owns a lock on the resource.

Returns:
true if this thread owns either a READ or WRITE lock on the resource.
Parameters:
lockit  lock object before checking *

const bool ResourceLock::lock const    LockType [inherited]
 

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.

Returns:
true if the resource is successfully locked; otherwise false.
Parameters:
LockType  Level of protection to apply.

const bool ResourceLock::unlock   [inherited]
 

Release the resource.

If one or more lock requests are pending, the oldest one is serviced.

Returns:
true if the resource is successfully unlocked; otherwise false.


Member Data Documentation

std::list<long> cbits::ResourceLock::_queue [protected, inherited]
 


The documentation for this class was generated from the following files:
Generated by
doxygen
Hosted by
SourceForge