Loading...
Searching...
No Matches
TfSpinRWMutex::ScopedLock Struct Reference

Scoped lock utility class. More...

#include <spinRWMutex.h>

Public Member Functions

 ScopedLock (TfSpinRWMutex &m, bool write=true)
 Construct a scoped lock for mutex m and acquire either a read or a write lock depending on write.
 
 ScopedLock (TfSpinRWMutex &m, TfSpinRWMutex::DeferAcquire)
 Construct a scoped lock associated with mutex m but not yet acquired.
 
 ScopedLock ()
 Construct a scoped lock not associated with a mutex.
 
 ScopedLock (ScopedLock &&other) noexcept
 Construct a new lock taking the other lock's mutex association and acquisition state.
 
ScopedLockoperator= (ScopedLock &&other) noexcept
 If this is not the same object as other, Release(), take the other lock's mutex association and acquisition state, and leave other not associated with a mutex.
 
 ~ScopedLock ()
 If this scoped lock is acquired for either read or write, Release() it.
 
void Acquire (TfSpinRWMutex &m, bool write=true)
 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.
 
void Acquire (bool write=true)
 Acquire either a read or write lock on this lock's associated mutex depending on write.
 
bool TryAcquire (TfSpinRWMutex &m, bool write=true)
 If the current scoped lock is acquired, Release() it, then associate this lock with m and try to acquire either a read or a write lock, depending on write.
 
bool TryAcquire (bool write=true)
 Try to acquire either a read or a write lock on this lock's associated mutex.
 
void Release ()
 Release the currently required lock on the associated mutex.
 
void AcquireRead ()
 Acquire a read lock on this lock's associated mutex.
 
bool TryAcquireRead ()
 Try to acquire a read lock on this lock's associated mutex.
 
void AcquireWrite ()
 Acquire a write lock on this lock's associated mutex.
 
bool TryAcquireWrite ()
 Try to acquire a write lock on this lock's associated mutex without waiting for other writers, but waiting for any currently active readers to release.
 
bool TryAcquireWriteIfReleased ()
 Try to acquire a write lock on this lock's associated mutex only if the mutex is in the fully released state (no readers, no writers).
 
bool UpgradeToWriter ()
 Change this lock's acquisition state from a read lock to a write lock.
 
bool DowngradeToReader ()
 Change this lock's acquisition state from a write lock to a read lock.
 

Detailed Description

Scoped lock utility class.

API modeled roughly after tbb::spin_rw_mutex::scoped_lock.

Definition at line 70 of file spinRWMutex.h.

Constructor & Destructor Documentation

◆ ScopedLock() [1/4]

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 74 of file spinRWMutex.h.

◆ ScopedLock() [2/4]

Construct a scoped lock associated with mutex m but not yet acquired.

Use Acquire(), AcquireRead(), AcquireWrite(), or any TryAcquire variant to acquire the lock.

Definition at line 83 of file spinRWMutex.h.

◆ ScopedLock() [3/4]

ScopedLock ( )
inline

Construct a scoped lock not associated with a mutex.

Definition at line 87 of file spinRWMutex.h.

◆ ScopedLock() [4/4]

ScopedLock ( ScopedLock &&  other)
inlinenoexcept

Construct a new lock taking the other lock's mutex association and acquisition state.

Leave other not associated with a mutex.

Definition at line 91 of file spinRWMutex.h.

◆ ~ScopedLock()

~ScopedLock ( )
inline

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

Definition at line 110 of file spinRWMutex.h.

Member Function Documentation

◆ Acquire() [1/2]

void 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 128 of file spinRWMutex.h.

◆ Acquire() [2/2]

void 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 117 of file spinRWMutex.h.

◆ AcquireRead()

void 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 173 of file spinRWMutex.h.

◆ AcquireWrite()

void 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 195 of file spinRWMutex.h.

◆ DowngradeToReader()

bool 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 251 of file spinRWMutex.h.

◆ operator=()

ScopedLock & operator= ( ScopedLock &&  other)
inlinenoexcept

If this is not the same object as other, Release(), take the other lock's mutex association and acquisition state, and leave other not associated with a mutex.

If this is the same object as other, do nothing. In either case, return *this.

Definition at line 99 of file spinRWMutex.h.

◆ Release()

void Release ( )
inline

Release the currently required lock on the associated mutex.

If this lock is not currently acquired, silently do nothing.

Definition at line 157 of file spinRWMutex.h.

◆ TryAcquire() [1/2]

bool TryAcquire ( bool  write = true)
inline

Try to acquire either a read or a write lock on this lock's associated mutex.

The lock must not already be acquired when calling TryAcquire(). Return true if the lock was successfully acquired, false if not.

Definition at line 151 of file spinRWMutex.h.

◆ TryAcquire() [2/2]

bool TryAcquire ( TfSpinRWMutex m,
bool  write = true 
)
inline

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

Return true if successfully acquired, false if not.

Definition at line 141 of file spinRWMutex.h.

◆ TryAcquireRead()

bool TryAcquireRead ( )
inline

Try to acquire a read lock on this lock's associated mutex.

The lock must not already be acquired when calling TryAcquireRead(). Return true if the lock was successfully acquired, false if not.

Definition at line 183 of file spinRWMutex.h.

◆ TryAcquireWrite()

bool TryAcquireWrite ( )
inline

Try to acquire a write lock on this lock's associated mutex without waiting for other writers, but waiting for any currently active readers to release.

The lock must not already be acquired when calling TryAcquireWrite(). Return true if the lock was successfully acquired (no other writer was active), false if not. Note: if readers are present but no other writer is active, this call blocks until those readers have released.

Definition at line 209 of file spinRWMutex.h.

◆ TryAcquireWriteIfReleased()

bool TryAcquireWriteIfReleased ( )
inline

Try to acquire a write lock on this lock's associated mutex only if the mutex is in the fully released state (no readers, no writers).

The lock must not already be acquired when calling TryAcquireWriteIfReleased(). Return true if the lock was successfully acquired, false if not. Never blocks.

Definition at line 224 of file spinRWMutex.h.

◆ UpgradeToWriter()

bool 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 238 of file spinRWMutex.h.


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