Logo Search packages:      
Sourcecode: virtualbox-ose version File versions

util::AutoReadLock Class Reference

#include <AutoLock.h>

List of all members.


Detailed Description

Provides safe management of read/write semaphores in read mode.

This class differs from the AutoWriteLock class is so that it's lock() and unlock() methods requests and release read (shared) locks on the managed read/write semaphore instead of write (exclusive) locks. See the AutoWriteLock class description for more information about read and write locks.

Safe semaphore management consists of the following:

Note that the LockHandle class taken by AutoReadLock constructors is an abstract base of the read/write semaphore. You should choose one of the existing subclasses of this abstract class or create your own subclass that implements necessary read and write lock semantics. The most suitable choice is the RWLockHandle class which provides full support for both read and write locks as describerd in AutoWriteLock docs. Alternatively, you can use the WriteLockHandle class if you only need write (exclusive) locking (WriteLockHandle requires less system resources and works faster).

However, please note that it absolutely does not make sense to manage WriteLockHandle semaphores with AutoReadLock instances because AutoReadLock instances will behave like AutoWriteLock instances in this case since WriteLockHandle provides only exclusive write locking. You have been warned.

A typical usage pattern of the AutoReadLock class is as follows: struct Struct : public RWLockHandle { ... };

void foo (Struct &aStruct) { { // acquire a read lock of aStruct (note that two foo() calls may be executed on separate threads simultaneously w/o blocking each other) AutoReadLock alock (aStruct);

// now we can read aStruct in a thread-safe manner if (aStruct.foo) ...;

// note that the read lock will be automatically released upon // execution of the return statement below if (!aStruct.bar) return;

... }

// note that the read lock is automatically released here }

Definition at line 892 of file AutoLock.h.


Public Member Functions

void attach (const Lockable *aLockable)
void attach (const Lockable &aLockable)
void attach (LockHandle &aHandle)
void attach (LockHandle *aHandle)
 AutoReadLock (const Lockable *aLockable)
 AutoReadLock (const Lockable &aLockable)
 AutoReadLock (LockHandle &aHandle)
 AutoReadLock (LockHandle *aHandle)
 AutoReadLock ()
bool belongsTo (const Lockable *aLockable)
bool belongsTo (const Lockable &aLockable)
bool belongsTo (const LockHandle *aHandle) const
bool belongsTo (const LockHandle &aHandle) const
void detach ()
bool isNull () const
void lock ()
bool operator! () const
void unlock ()
 ~AutoReadLock ()

Private Attributes

LockHandlemHandle
uint32_t mLockLevel

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index