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

Scoped lock utility class. More...

#include <spinMutex.h>

Public Member Functions

 ScopedLock (TfSpinMutex &m)
 Construct a scoped lock for mutex m and acquire a lock.
 
 ScopedLock (TfSpinMutex &m, TfSpinMutex::DeferAcquire)
 Construct a scoped lock associated with mutex m but not yet acquired.
 
 ScopedLock ()=default
 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, Release() it.
 
void Acquire (TfSpinMutex &m)
 If the current scoped lock is acquired, Release() it, then associate this lock with m and acquire a lock.
 
void Release ()
 Release the currently required lock on the associated mutex.
 
void Acquire ()
 Acquire a lock on this lock's associated mutex.
 
bool TryAcquire (TfSpinMutex &m)
 If the current scoped lock is acquired, Release() it, then associate this lock with m and try to acquire a lock.
 
bool TryAcquire ()
 Try to acquire a lock on this lock's associated mutex.
 

Detailed Description

Scoped lock utility class.

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

Definition at line 58 of file spinMutex.h.

Constructor & Destructor Documentation

◆ ScopedLock() [1/4]

ScopedLock ( TfSpinMutex m)
inlineexplicit

Construct a scoped lock for mutex m and acquire a lock.

Definition at line 61 of file spinMutex.h.

◆ ScopedLock() [2/4]

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

Use Acquire() or TryAcquire() to acquire the lock.

Definition at line 67 of file spinMutex.h.

◆ ScopedLock() [3/4]

ScopedLock ( )
default

Construct a scoped lock not associated with a mutex.

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

◆ ~ScopedLock()

~ScopedLock ( )
inline

If this scoped lock is acquired, Release() it.

Definition at line 92 of file spinMutex.h.

Member Function Documentation

◆ Acquire() [1/2]

void Acquire ( )
inline

Acquire a lock on this lock's associated mutex.

This lock must not already be acquired when calling Acquire().

Definition at line 114 of file spinMutex.h.

◆ Acquire() [2/2]

void Acquire ( TfSpinMutex m)
inline

If the current scoped lock is acquired, Release() it, then associate this lock with m and acquire a lock.

Definition at line 98 of file spinMutex.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 82 of file spinMutex.h.

◆ Release()

void Release ( )
inline

Release the currently required lock on the associated mutex.

If this lock is not currently acquired, do nothing.

Definition at line 106 of file spinMutex.h.

◆ TryAcquire() [1/2]

bool TryAcquire ( )
inline

Try to acquire a 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 133 of file spinMutex.h.

◆ TryAcquire() [2/2]

bool TryAcquire ( TfSpinMutex m)
inline

If the current scoped lock is acquired, Release() it, then associate this lock with m and try to acquire a lock.

Return true if the lock was successfully acquired, false if not.

Definition at line 124 of file spinMutex.h.


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