7 #ifndef PXR_BASE_TF_SPIN_RW_MUTEX_H
8 #define PXR_BASE_TF_SPIN_RW_MUTEX_H
52 static constexpr
int OneReader = 2;
53 static constexpr
int WriterFlag = 1;
164 void _ReleaseRead() {
170 void _ReleaseWrite() {
185 if (
ARCH_LIKELY(!(_lockState.fetch_add(OneReader) & WriterFlag))) {
193 _lockState -= OneReader;
214 _lockState -= OneReader;
221 int state = _lockState.fetch_or(WriterFlag);
222 if (!(state & WriterFlag)) {
249 _lockState &= ~WriterFlag;
264 int state = _lockState.fetch_or(WriterFlag);
265 if (!(state & WriterFlag)) {
268 if (_lockState.fetch_sub(
269 OneReader) != (OneReader | WriterFlag)) {
289 _lockState += (OneReader-1);
297 enum _StagedAcquireWriteState {
310 _StagedAcquireWriteState
311 _StagedAcquireWriteStep(_StagedAcquireWriteState curState) {
314 case _StageNotAcquired:
315 state = _lockState.fetch_or(WriterFlag);
316 if (!(state & WriterFlag)) {
319 return state == 0 ? _StageAcquired : _StageAcquiring;
322 return _StageNotAcquired;
323 case _StageAcquiring:
326 return _StageAcquired;
329 return _StageAcquired;
333 TF_API void _WaitForReaders()
const;
334 TF_API void _WaitForWriter()
const;
336 std::atomic<int> _lockState;
341 #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)