Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SbThreadAutoReadLock Class Reference

VSG extension Provides reliable unlocking of a read-only mutex. More...

#include <Inventor/threads/SbThreadAutoLock.h>

Public Member Functions

 SbThreadAutoReadLock (SbThreadRWMutex *mutex)
 Creates a mutex "autolock" object and automatically calls the mutex readlock method.
 
 SbThreadAutoReadLock (SbThreadRWMutex &mutex)
 
int unlock ()
 Explicitly unlock the associated mutex.
 
int relock ()
 Explicitly relock the associated mutex.
 

Detailed Description

VSG extension Provides reliable unlocking of a read-only mutex.

This class provides reliable unlocking of a read-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:

myClass contains an RWMutex object named m_mutex
void myClass::someFunction()
{
... other code ...
} // mutex automatically unlocked
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Provides reliabl...

SEE ALSO

SbThread, SbThreadAutoLock, SbThreadAutoWriteLock, SbThreadBarrier, SbThreadMutex, SbThreadRWMutex

Definition at line 146 of file SbThreadAutoLock.h.

Constructor & Destructor Documentation

◆ SbThreadAutoReadLock() [1/2]

SbThreadAutoReadLock::SbThreadAutoReadLock ( SbThreadRWMutex mutex)

Creates a mutex "autolock" object and automatically calls the mutex readlock method.

The mutex will be automatically unlocked when the autolock object is destroyed.

◆ SbThreadAutoReadLock() [2/2]

SbThreadAutoReadLock::SbThreadAutoReadLock ( SbThreadRWMutex mutex)

Member Function Documentation

◆ relock()

int SbThreadAutoReadLock::relock ( )

Explicitly relock the associated mutex.

Do not unlock or lock the mutex directly.

◆ unlock()

int SbThreadAutoReadLock::unlock ( )

Explicitly unlock the associated mutex.

Do not unlock or lock the mutex directly.


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