In file thread/gmutex.hh:

class semlock

Class to automatically lock and unlock a mutex.

Inheritance:


Public Fields

rdlock
read lock
wrlock
write lock

Public Methods

explicit semlock (abstractsemaphore& sem)
Default constructor.
semlock (abstractsemaphore& sem, locktype lck)
Default constructor.
virtual ~semlock ()
Default destructor.

Public

typedef enum locktype
type of lock

Documentation

This class can be used to automatically lock and unlock a semaphore over the duration of a function call. semlock has to be initialized with an mutex, a recursive mutex or a read/write lock. Upon contruction of the object the semaphore is locked. When the object is destroyed the semaphore is automatically freed.

 
    Example:

    mutex	mux;
    void foobar () {
       mutexlock	lockit (mux);
       // statements of foobar here
    }
    

Since an object is automatically destroyed at the end of its context, semlock can also be used in loops and branches of conditional statments, or in any compound statement to protect a resource for the duration of the context.

typedef enum locktype
type of lock

rdlock
read lock

wrlock
write lock

explicit semlock(abstractsemaphore& sem)
Constructs a semmutex object and locks the semaphore.
Returns:
void
Parameters:
sem - reference to a semaphore to be locked

semlock(abstractsemaphore& sem, locktype lck)
Constructs a semmutex object and locks the semaphore. The second argument specifies whether a read or write lock is applied.
Returns:
void
Parameters:
sem - reference to a semaphore to be locked

virtual ~semlock()
Destructs the semmutex object and unlocks the semaphore.
Returns:
void


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++