]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/ReadWriteLock.cc
2 * DEBUG: section 54 Interprocess Communication
6 #include "ipc/ReadWriteLock.h"
10 Ipc::ReadWriteLock::lockShared()
12 ++readLevel
; // this locks "new" writers out
13 if (!writeLevel
|| appending
) { // nobody is writing, or sharing is OK
22 Ipc::ReadWriteLock::lockExclusive()
24 if (!writeLevel
++) { // we are the first writer + lock "new" readers out
25 if (!readLevel
) { // no old readers and nobody is becoming one
35 Ipc::ReadWriteLock::unlockShared()
43 Ipc::ReadWriteLock::unlockExclusive()
52 Ipc::ReadWriteLock::switchExclusiveToShared()
55 ++readLevel
; // must be done before we release exclusive control
61 Ipc::ReadWriteLock::startAppending()
68 Ipc::ReadWriteLock::updateStats(ReadWriteLockStats
&stats
) const
72 stats
.readers
+= readers
;
76 stats
.appenders
+= appending
;
83 /* Ipc::ReadWriteLockStats */
85 Ipc::ReadWriteLockStats::ReadWriteLockStats()
87 memset(this, 0, sizeof(*this));
91 Ipc::ReadWriteLockStats::dump(StoreEntry
&e
) const
93 storeAppendPrintf(&e
, "Available locks: %9d\n", count
);
98 storeAppendPrintf(&e
, "Reading: %9d %6.2f%%\n",
99 readable
, (100.0 * readable
/ count
));
100 storeAppendPrintf(&e
, "Writing: %9d %6.2f%%\n",
101 writeable
, (100.0 * writeable
/ count
));
102 storeAppendPrintf(&e
, "Idle: %9d %6.2f%%\n",
103 idle
, (100.0 * idle
/ count
));
105 if (readers
|| writers
) {
106 const int locked
= readers
+ writers
;
107 storeAppendPrintf(&e
, "Readers: %9d %6.2f%%\n",
108 readers
, (100.0 * readers
/ locked
));
109 const double appPerc
= writers
? (100.0 * appenders
/ writers
) : 0.0;
110 storeAppendPrintf(&e
, "Writers: %9d %6.2f%% including Appenders: %9d %6.2f%%\n",
111 writers
, (100.0 * writers
/ locked
),