Provides reliable unlocking of a write-only mutex. More...
#include <Inventor/threads/SbThreadAutoLock.h>
Public Member Functions | |
SbThreadAutoWriteLock (SbThreadRWMutex *mutex) | |
Creates a mutex "autolock" object and automatically calls the mutex writelock method. | |
SbThreadAutoWriteLock (SbThreadRWMutex &mutex) | |
int | unlock () |
Explicitly unlock the associated mutex. | |
int | relock () |
Explicitly relock the associated mutex. | |
Provides reliable unlocking of a write-only mutex.
This class provides reliable unlocking of a write-only mutex.
An SbThreadRWMutex object must be created separately. The address of the mutex object is passed to the constructor, which locks the mutex and saves a reference to the mutex object. The autolock object should be created on the stack, so each thread will have its own autolock. The destructor automatically unlocks the mutex.
Because the autolock object is created on the stack, it avoids the need to explicitly unlock the mutex at every point of exit from the function (a common source of errors). The mutex will be unlocked when the autolock goes out of scope.
The unlock() and relock() methods are provided for complex cases where the lock needs to be temporarily released. If the autolock is explicitly unlocked, the destructor does nothing.
Example:
SbThread, SbThreadAutoLock, SbThreadAutoReadLock, SbThreadBarrier, SbThreadMutex, SbThreadRWMutex
Definition at line 225 of file SbThreadAutoLock.h.
SbThreadAutoWriteLock::SbThreadAutoWriteLock | ( | SbThreadRWMutex * | mutex | ) |
Creates a mutex "autolock" object and automatically calls the mutex writelock method.
The mutex will be automatically unlocked when the autolock object is destroyed.
SbThreadAutoWriteLock::SbThreadAutoWriteLock | ( | SbThreadRWMutex & | mutex | ) |
int SbThreadAutoWriteLock::relock | ( | ) |
Explicitly relock the associated mutex.
Do not unlock or lock the mutex directly.
int SbThreadAutoWriteLock::unlock | ( | ) |
Explicitly unlock the associated mutex.
Do not unlock or lock the mutex directly.