};
// Reader-writer mutex.
-class MUTEX Mutex {
+// Derive from CheckedMutex for the purposes of EBO.
+// We could make it a field marked with [[no_unique_address]],
+// but this attribute is not supported by some older compilers.
+class MUTEX Mutex : CheckedMutex {
public:
- constexpr Mutex(MutexType type = MutexUnchecked) : checked_(type) {}
+ constexpr Mutex(MutexType type = MutexUnchecked) : CheckedMutex(type) {}
void Lock() ACQUIRE() {
- checked_.Lock();
+ CheckedMutex::Lock();
u64 reset_mask = ~0ull;
u64 state = atomic_load_relaxed(&state_);
const uptr kMaxSpinIters = 1500;
}
void Unlock() RELEASE() {
- checked_.Unlock();
+ CheckedMutex::Unlock();
bool wake_writer;
u64 wake_readers;
u64 new_state;
}
void ReadLock() ACQUIRE_SHARED() {
- checked_.Lock();
+ CheckedMutex::Lock();
bool locked;
u64 new_state;
u64 state = atomic_load_relaxed(&state_);
}
void ReadUnlock() RELEASE_SHARED() {
- checked_.Unlock();
+ CheckedMutex::Unlock();
bool wake;
u64 new_state;
u64 state = atomic_load_relaxed(&state_);
}
private:
- [[no_unique_address]] CheckedMutex checked_;
atomic_uint64_t state_ = {0};
Semaphore writers_;
Semaphore readers_;