18 #ifndef ION_BASE_READWRITELOCK_H_
19 #define ION_BASE_READWRITELOCK_H_
68 void UnlockForWrite();
76 std::atomic<int> reader_count_;
77 std::atomic<int> writer_count_;
93 void Lock() { lock_.LockForRead(); }
96 void Unlock() { lock_.UnlockForRead(); }
101 bool IsLocked()
const {
return lock_.GetReaderCount() > 0; }
106 DISALLOW_IMPLICIT_CONSTRUCTORS(
ReadLock);
118 void Lock() { lock_.LockForWrite(); }
121 void Unlock() { lock_.UnlockForWrite(); }
124 bool IsLocked()
const {
return lock_.GetWriterCount() > 0; }
129 DISALLOW_IMPLICIT_CONSTRUCTORS(
WriteLock);
135 #endif // ION_BASE_READWRITELOCK_H_
void Lock()
"Locks" the lock for reading, which may or may not block.
A Semaphore enables threads and process synchronization.
void Unlock()
"Unlocks" the lock for reading, which may allow other writers to proceed.
int GetWriterCount() const
Returns the number of writers in this lock.
ReadLock(ReadWriteLock *lock)
The passed pointer must be non-NULL.
bool IsLocked() const
Returns whether there are any readers in the lock.
The ReadWriteLock class defines a non-promotable lock that is very fast when only readers try to obta...
void Lock()
"Locks" the lock for writing, which blocks if there are any readers or writers holding the lock...
A WriteLock obtains a write lock, but has a similar interface to a Mutex and can be used with a Write...
void Unlock()
"Unlocks" the lock for writing, which may allow other readers or writers to proceed.
int GetReaderCount() const
Returns the number of readers in this lock.
A ReadLock obtains a read lock, but has a similar interface to a Mutex and can be used with a ReadGua...
WriteLock(ReadWriteLock *lock)
The passed pointer must be non-NULL.
A Mutex is used to ensure that only one thread or process can access a block of code at one time...
bool IsLocked() const
Returns whether there are any writers in the lock.