
A guard is an object that releases a lock, that was aquired by the creator of the guard, when it goes out of scope. The lock ownership is transferred when a guard is copied. On assignment a held lock is unlocked and the ownership is transferred.
This class provides a guard for a RwMutex.
Definition at line 330 of file mutex.h.
| typedef int(RwMutex::*) OSB_LIB::RwGuard::Unlock() |
Create a RwGuard.
If used as default constructor, i.e. without providing a mutex, the guard should behave as if it was locked. This makes it possible to verify the correct usage of guard with respect to copying and assignment.
| locked | Flag if the caller of the function owns the appropriate lock when the constructor is called (true is yes, false if no). | |
| pMutex | RwMutex to unlock. | |
| unlock | Unlock function to call: either RwMutex::readUnlock or RwMutex::writeUnlock. |
| OSB_LIB::RwGuard::~RwGuard | ( | ) |
The destructor calls the unlock function if the destructed object owns the lock.
| OSB_LIB::RwGuard::RwGuard | ( | RwGuard & | rhs | ) |
Non-const copy constructor, takes the lock ownership from `rhs'.
| OSB_LIB::RwGuard::RwGuard | ( | RwGuardRef | r | ) |
Construct from a RwGuardRef, takes the lock ownership from `r'.
| bool OSB_LIB::RwGuard::locked | ( | ) | const [inline] |
Lock owned by the current object?
Definition at line 415 of file mutex.h.
References locked_.
Referenced by OSB_LIB::ResourceList< R >::clear(), OSB_LIB::ResourceList< R >::erase(), OSB_LIB::ResourceList< R >::insert(), and OSB_LIB::ResourceList< R >::replace().
| OSB_LIB::RwGuard::operator RwGuardRef | ( | ) |
Convert to a RwGuardRef.
Non-const assignment operator.
The assignment operator first unlocks a held lock and then transfers the lock ownership.
| bool OSB_LIB::RwGuard::release | ( | ) |
Release lock ownership without unlocking the mutex.
| void OSB_LIB::RwGuard::unlock | ( | ) |
Call the unlock function.
If the object owns the lock the mutex's unlock function is called. The function always sets `locked_' to false.
bool OSB_LIB::RwGuard::locked_ [private] |
RwMutex* OSB_LIB::RwGuard::pMutex_ [private] |
Unlock OSB_LIB::RwGuard::unlock_ [private] |
1.4.7