In file thread/gmutex.hh:

class readwritelock : public abstractsemaphore

Class to store a read/write lock.

Inheritance:


Public Methods

explicit readwritelock (int Maxuse = -1)
Default constructor.
virtual ~readwritelock ()
Default destructor.
readwritelock (const readwritelock& rw)
Copy constructor.
readwritelock& operator= (const readwritelock&)
Assignment operator.
virtual void readlock ()
Read/write-lock lock function.
virtual void writelock ()
Read/write-lock lock function.
virtual void lock ()
Read/write-lock lock function.
virtual void unlock ()
Read/write-lock unlock function.
bool trylock (locktype lck = rdlock)
Read/write-lock trylock function.

Inherited from abstractsemaphore:

Public Fields

rdlock
wrlock

Public Methods

virtual bool trylock_timed(int timeout, locktype lck = rdlock)

Public

typedef enum locktype

Documentation

This class is used to implement a read/write lock. A read/write lock can be locked by multple readers simultaneously. A writer owns the lock exclusively. The maximum number of readers can be specified during creation. Writers have priority over readers, meaning if a request from a writer is pending, no further read access is granted. Then, after all readers have returned the lock, the writer will get granted access first. When passing a read/write lock object to a function it has to be passed by reference or by pointer (never by value because the copy operator is disabled for read/write locks).

explicit readwritelock(int Maxuse = -1)
Constructs a read/write lock. Takes the maxumum number of concurrent read locks as argument; a number equal or less zero represents unlimited read access.
Returns:
void
Parameters:
Maxuse - maximum number of readers

virtual ~readwritelock()
Destructs the read/write lock.
Returns:
void

readwritelock(const readwritelock& rw)
Constructs a read/write lock, overwritting the default copy constructor by creating a new read/write lock.
Returns:
void

readwritelock& operator= (const readwritelock&)
Overrides the default assignment behaviour. Does nothing.
Returns:
refrence to object
Parameters:
readwritelock - copy argument

virtual void readlock()
Locks the lock for read. Multiple read locks (up to maxuse) can be granted, but only one write lock at any given time. If a write lock is requested while the lock is given to one or more readers, no further read locks will be granted to prevent the write task from starvation. (Write locks have absolute priority.)
Returns:
void

virtual void writelock()
Locks the lock for write. Multiple read locks (up to maxuse) can be granted, but only one write lock at any given time. If a write lock is requested while the lock is given to one or more readers, no further read locks will be granted to prevent the write task from starvation. (Write locks have absolute priority.)
Returns:
void

virtual void lock()
Locks the lock for read; same as readlock().
Returns:
void

virtual void unlock()
Read/write-lock unlock function.
Returns:
void

bool trylock(locktype lck = rdlock)
Trys to lock the read/write lock. To return true and locked, either a writer attemps to lock a free lock, or a reader attemps to obtain a lock which is not owned by a writer. Otherwise the function returns false and without the lock.

Returns:
true if locked, false otherwise
Parameters:
write - true for a write lock, false for a read lock


This class has no child classes.
Author:
DS, November 98
See Also:
Recursive mutex objects

alphabetic index hierarchy of classes


Please send questions and comments to zweizig_j@ligo.caltech.edu


generated by doc++