Set writer_thread_id earlier, when new exclusive owener is waiting for existing readers to finish

This commit is contained in:
Alexander Gololobov 2024-07-22 12:11:56 +02:00
parent 55d1656f4d
commit bb0b29f6e5
2 changed files with 5 additions and 3 deletions

View File

@ -31,11 +31,13 @@ void SharedMutex::lock()
break;
}
/// The first step of acquiring the exclusive ownership is finished.
/// Now we just wait until all readers release the shared ownership.
writer_thread_id.store(getThreadId());
value |= writers;
while (value & readers)
futexWaitLowerFetch(state, value);
writer_thread_id.store(getThreadId());
}
bool SharedMutex::try_lock()

View File

@ -38,7 +38,7 @@ private:
alignas(64) std::atomic<UInt64> state;
std::atomic<UInt32> waiters;
/// Is set while the lock is held in exclusive mode only to facilitate debugging
/// Is set while the lock is held (or is in the process of being acquired) in exclusive mode only to facilitate debugging
std::atomic<UInt64> writer_thread_id;
};