24 #ifndef PXR_BASE_TF_SPIN_RW_MUTEX_H
25 #define PXR_BASE_TF_SPIN_RW_MUTEX_H
69 static constexpr
int OneReader = 2;
70 static constexpr
int WriterFlag = 1;
181 void _ReleaseRead() {
187 void _ReleaseWrite() {
202 if (
ARCH_LIKELY(!(_lockState.fetch_add(OneReader) & WriterFlag))) {
210 _lockState -= OneReader;
231 _lockState -= OneReader;
238 int state = _lockState.fetch_or(WriterFlag);
239 if (!(state & WriterFlag)) {
266 _lockState &= ~WriterFlag;
281 int state = _lockState.fetch_or(WriterFlag);
282 if (!(state & WriterFlag)) {
285 if (_lockState.fetch_sub(
286 OneReader) != (OneReader | WriterFlag)) {
306 _lockState += (OneReader-1);
314 enum _StagedAcquireWriteState {
327 _StagedAcquireWriteState
328 _StagedAcquireWriteStep(_StagedAcquireWriteState curState) {
331 case _StageNotAcquired:
332 state = _lockState.fetch_or(WriterFlag);
333 if (!(state & WriterFlag)) {
336 return state == 0 ? _StageAcquired : _StageAcquiring;
339 return _StageNotAcquired;
340 case _StageAcquiring:
343 return _StageAcquired;
346 return _StageAcquired;
350 TF_API void _WaitForReaders()
const;
351 TF_API void _WaitForWriter()
const;
353 std::atomic<int> _lockState;
358 #endif // PXR_BASE_TF_SPIN_RW_MUTEX_H
ScopedLock()
Construct a scoped lock not associated with a mutex.
static constexpr int ReadAcquired
void Acquire(bool write=true)
#define TF_DEV_AXIOM(cond)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
TfSpinRWMutex()
Construct a mutex, initially unlocked.
static constexpr int NotAcquired
#define PXR_NAMESPACE_CLOSE_SCOPE
static constexpr int WriteAcquired
void ReleaseWrite()
Release this thread's write lock on this mutex.
void ReleaseRead()
Release this thread's read lock on this mutex.
ScopedLock(TfSpinRWMutex &m, bool write=true)
void Acquire(TfSpinRWMutex &m, bool write=true)