7#ifndef PXR_BASE_TF_SPIN_MUTEX_H
8#define PXR_BASE_TF_SPIN_MUTEX_H
11#include "pxr/base/tf/api.h"
19PXR_NAMESPACE_OPEN_SCOPE
75 : _mutex(std::exchange(other._mutex,
nullptr))
76 , _acquired(std::exchange(other._acquired,
false)) {}
85 _mutex = std::exchange(other._mutex,
nullptr);
86 _acquired = std::exchange(other._acquired,
false);
149 bool _acquired =
false;
157 return _lockState.exchange(
true, std::memory_order_acquire) ==
false;
172 _lockState.store(
false, std::memory_order_release);
177 TF_API
void _AcquireContended();
179 std::atomic<bool> _lockState;
182PXR_NAMESPACE_CLOSE_SCOPE
This class implements a simple spin lock that emphasizes throughput when there is little to no conten...
TfSpinMutex()
Construct a mutex, initially unlocked.
static constexpr DeferAcquire deferAcquire
Tag value for deferred-acquisition ScopedLock construction.
void Release()
Release this thread's lock on this mutex.
void Acquire()
Acquire a lock on this mutex.
bool TryAcquire()
Acquire a lock on this mutex if it is not currently held by another thread.
Tag type for constructing a ScopedLock associated with a mutex but not yet acquired.
Stripped down version of diagnostic.h that doesn't define std::string.
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
Scoped lock utility class.
void Acquire(TfSpinMutex &m)
If the current scoped lock is acquired, Release() it, then associate this lock with m and acquire a l...
ScopedLock(ScopedLock &&other) noexcept
Construct a new lock taking the other lock's mutex association and acquisition state.
ScopedLock()=default
Construct a scoped lock not associated with a mutex.
void Release()
Release the currently required lock on the associated mutex.
ScopedLock(TfSpinMutex &m)
Construct a scoped lock for mutex m and acquire a lock.
ScopedLock & operator=(ScopedLock &&other) noexcept
If this is not the same object as other, Release(), take the other lock's mutex association and acqui...
void Acquire()
Acquire a lock on this lock's associated mutex.
~ScopedLock()
If this scoped lock is acquired, Release() it.
bool TryAcquire(TfSpinMutex &m)
If the current scoped lock is acquired, Release() it, then associate this lock with m and try to acqu...
bool TryAcquire()
Try to acquire a lock on this lock's associated mutex.
ScopedLock(TfSpinMutex &m, TfSpinMutex::DeferAcquire)
Construct a scoped lock associated with mutex m but not yet acquired.