Provides reliable unlocking of a spinlock. More...
#include <Inventor/threads/SbThreadSpinlock.h>
Public Member Functions | |
SbThreadAutoSpinlock (SbThreadSpinlock *spinlock) | |
SbThreadAutoSpinlock (SbThreadSpinlock &spinlock) |
This class provides reliable unlocking of a spinlock.
An SbThreadMutex object must be created separately. The address of the spinlock object is passed to the constructor, which locks the spinlock and saves a reference to the spinlock object. The autolock object should be created on the stack, so each thread will have its own autolock. The destructor automatically unlocks the spinlock.
Because the autolock object is created on the stack, it avoids the need to explicitly unlock the spinlock at every point of exit from the function (a common source of errors). The spinlock will be unlocked when the autolock goes out of scope.
Example:
// myClass contains a Mutex object named m_mutex void myClass::someFunction() { // m_spinlock is a ptr to an existing SbThreadSpinlock object SbThreadAutoSpinlock dummyName( m_spinlock ); ... other code ... } // spinlock automatically unlocked
SbThreadAutoSpinlock::SbThreadAutoSpinlock | ( | SbThreadSpinlock * | spinlock | ) | [inline] |
Creates a spinlock "autolock" object and automatically calls the mutex lock method.
The spinlock will be automatically unlocked when the autolock object is destroyed.
SbThreadAutoSpinlock::SbThreadAutoSpinlock | ( | SbThreadSpinlock & | spinlock | ) | [inline] |