]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/ReadWriteLock.cc
7fc164fb1a9ce0b4b3a7475930a07425a0c23a47
4 * DEBUG: section 54 Interprocess Communication
10 #include "ipc/ReadWriteLock.h"
13 Ipc::ReadWriteLock::lockShared()
15 ++readers
; // this locks "new" writers out
16 if (!writers
) // there are no old writers
23 Ipc::ReadWriteLock::lockExclusive()
25 if (!writers
++) { // we are the first writer + this locks "new" readers out
26 if (!readers
) // there are no old readers
34 Ipc::ReadWriteLock::unlockShared()
36 assert(readers
-- > 0);
40 Ipc::ReadWriteLock::unlockExclusive()
42 assert(writers
-- > 0);
46 Ipc::ReadWriteLock::switchExclusiveToShared()
48 ++readers
; // must be done before we release exclusive control
53 Ipc::ReadWriteLock::updateStats(ReadWriteLockStats
&stats
) const
57 stats
.readers
+= readers
;
60 stats
.writers
+= writers
;
68 /* Ipc::ReadWriteLockStats */
70 Ipc::ReadWriteLockStats::ReadWriteLockStats()
72 memset(this, 0, sizeof(*this));
76 Ipc::ReadWriteLockStats::dump(StoreEntry
&e
) const
78 storeAppendPrintf(&e
, "Available locks: %9d\n", count
);
83 storeAppendPrintf(&e
, "Reading: %9d %6.2f%%\n",
84 readable
, (100.0 * readable
/ count
));
85 storeAppendPrintf(&e
, "Writing: %9d %6.2f%%\n",
86 writeable
, (100.0 * writeable
/ count
));
87 storeAppendPrintf(&e
, "Idle: %9d %6.2f%%\n",
88 idle
, (100.0 * idle
/ count
));
90 if (readers
|| writers
) {
91 const int locked
= readers
+ writers
;
92 storeAppendPrintf(&e
, "Readers: %9d %6.2f%%\n",
93 readers
, (100.0 * readers
/ locked
));
94 storeAppendPrintf(&e
, "Writers: %9d %6.2f%%\n",
95 writers
, (100.0 * writers
/ locked
));