20 assert(flag.test_and_set(std::memory_order_relaxed));
44 if (!writeLevel || appending) {
56 return finalizeExclusive();
66 if (!updating.test_and_set(std::memory_order_acquire))
95 updating.clear(std::memory_order_release);
114 return finalizeExclusive();
153 }
else if (writing) {
167 memset(
this, 0,
sizeof(*
this));
179 readable, (100.0 * readable / count));
181 writeable, (100.0 * writeable / count));
183 idle, (100.0 * idle / count));
185 if (readers || writers) {
186 const int locked = readers + writers;
188 readers, (100.0 * readers / locked));
189 const double appPerc = writers ? (100.0 * appenders / writers) : 0.0;
191 writers, (100.0 * writers / locked),
199 return os << lock.
readers <<
'R' <<
approximate stats of a set of ReadWriteLocks
int readable
number of locks locked for reading
int idle
number of unlocked locks
int writers
sum of lock.writers
int count
the total number of locks
void dump(StoreEntry &e) const
int writeable
number of locks locked for writing
int readers
sum of lock.readers
int appenders
number of appending writers
void unlockHeaders()
undo successful lockHeaders()
std::atomic< uint32_t > readLevel
number of users reading (or trying to)
void switchExclusiveToShared()
bool lockHeaders()
lock for [readable] metadata update or return false
std::atomic< uint32_t > readers
number of reading users
void unlockExclusive()
undo successful exclusiveLock()
bool lockExclusive()
lock for modification or return false
bool stopAppendingAndRestoreExclusive()
std::atomic< uint32_t > writeLevel
number of users writing (or trying to write)
std::atomic< bool > writing
there is a writing user (there can be at most 1)
bool unlockSharedAndSwitchToExclusive()
std::atomic< bool > appending
the writer has promised to only append
void unlockShared()
undo successful sharedLock()
bool lockShared()
lock for reading or return false
void updateStats(ReadWriteLockStats &stats) const
adds approximate current stats to the supplied ones
void startAppending()
writer keeps its lock but also allows reading
void AssertFlagIsSet(std::atomic_flag &flag)
std::ostream & operator<<(std::ostream &os, const QuestionerId &qid)
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)