HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfSpinRWMutex::ScopedLock Struct Reference

#include <spinRWMutex.h>

Public Member Functions

 ScopedLock (TfSpinRWMutex &m, bool write=true)
 
 ScopedLock ()
 Construct a scoped lock not associated with a mutex. More...
 
 ~ScopedLock ()
 
void Acquire (TfSpinRWMutex &m, bool write=true)
 
void Acquire (bool write=true)
 
void Release ()
 
void AcquireRead ()
 
void AcquireWrite ()
 
bool UpgradeToWriter ()
 
bool DowngradeToReader ()
 

Static Public Attributes

static constexpr int NotAcquired = 0
 
static constexpr int ReadAcquired = 1
 
static constexpr int WriteAcquired = 2
 

Detailed Description

Scoped lock utility class. API modeled roughly after tbb::spin_rw_mutex::scoped_lock.

Definition at line 79 of file spinRWMutex.h.

Constructor & Destructor Documentation

TfSpinRWMutex::ScopedLock::ScopedLock ( TfSpinRWMutex m,
bool  write = true 
)
inlineexplicit

Construct a scoped lock for mutex m and acquire either a read or a write lock depending on write.

Definition at line 88 of file spinRWMutex.h.

TfSpinRWMutex::ScopedLock::ScopedLock ( )
inline

Construct a scoped lock not associated with a mutex.

Definition at line 95 of file spinRWMutex.h.

TfSpinRWMutex::ScopedLock::~ScopedLock ( )
inline

If this scoped lock is acquired for either read or write, Release() it.

Definition at line 99 of file spinRWMutex.h.

Member Function Documentation

void TfSpinRWMutex::ScopedLock::Acquire ( TfSpinRWMutex m,
bool  write = true 
)
inline

If the current scoped lock is acquired, Release() it, then associate this lock with m and acquire either a read or a write lock, depending on write.

Definition at line 106 of file spinRWMutex.h.

void TfSpinRWMutex::ScopedLock::Acquire ( bool  write = true)
inline

Acquire either a read or write lock on this lock's associated mutex depending on write. This lock must be associated with a mutex (typically by construction or by a call to Acquire() that takes a mutex). This lock must not already be acquired when calling Acquire().

Definition at line 117 of file spinRWMutex.h.

void TfSpinRWMutex::ScopedLock::AcquireRead ( )
inline

Acquire a read lock on this lock's associated mutex. This lock must not already be acquired when calling AcquireRead().

Definition at line 144 of file spinRWMutex.h.

void TfSpinRWMutex::ScopedLock::AcquireWrite ( )
inline

Acquire a write lock on this lock's associated mutex. This lock must not already be acquired when calling AcquireWrite().

Definition at line 152 of file spinRWMutex.h.

bool TfSpinRWMutex::ScopedLock::DowngradeToReader ( )
inline

Change this lock's acquisition state from a write lock to a read lock. This lock must already be acquired for writing. Return true if the downgrade occurred without releasing the write in the interim, false if it was released and other writers may have intervened.

Definition at line 173 of file spinRWMutex.h.

void TfSpinRWMutex::ScopedLock::Release ( )
inline

Release the currently required lock on the associated mutex. If this lock is not currently acquired, silently do nothing.

Definition at line 128 of file spinRWMutex.h.

bool TfSpinRWMutex::ScopedLock::UpgradeToWriter ( )
inline

Change this lock's acquisition state from a read lock to a write lock. This lock must already be acquired for reading. Return true if the upgrade occurred without releasing the read lock, false if it was released.

Definition at line 162 of file spinRWMutex.h.

Member Data Documentation

constexpr int TfSpinRWMutex::ScopedLock::NotAcquired = 0
static

Definition at line 82 of file spinRWMutex.h.

constexpr int TfSpinRWMutex::ScopedLock::ReadAcquired = 1
static

Definition at line 83 of file spinRWMutex.h.

constexpr int TfSpinRWMutex::ScopedLock::WriteAcquired = 2
static

Definition at line 84 of file spinRWMutex.h.


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