SbThreadAutoSpinlock Class Reference
[Threads]

VSG extension Provides reliable unlocking of a spinlock. More...

#include <Inventor/threads/SbThreadSpinlock.h>

List of all members.

Public Member Functions

 SbThreadAutoSpinlock (SbThreadSpinlock *spinlock)
 SbThreadAutoSpinlock (SbThreadSpinlock &spinlock)

Detailed Description

VSG extension Provides reliable unlocking of a 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

SEE ALSO

SbThread, SbThreadSpinlock


Constructor & Destructor Documentation

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]

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

Open Inventor Toolkit reference manual, generated on 12 Feb 2024
Copyright © Thermo Fisher Scientific All rights reserved.
http://www.openinventor.com/