]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/ReadWriteLock.cc
4 * DEBUG: section 54 Interprocess Communication
9 #include "ipc/ReadWriteLock.h"
12 Ipc::ReadWriteLock::lockShared()
14 ++readers
; // this locks "new" writers out
15 if (!writers
) // there are no old writers
22 Ipc::ReadWriteLock::lockExclusive()
24 if (!writers
++) { // we are the first writer + this locks "new" readers out
25 if (!readers
) // there are no old readers
33 Ipc::ReadWriteLock::unlockShared()
35 assert(readers
-- > 0);
39 Ipc::ReadWriteLock::unlockExclusive()
41 assert(writers
-- > 0);
45 Ipc::ReadWriteLock::switchExclusiveToShared()
47 ++readers
; // must be done before we release exclusive control
52 Ipc::ReadWriteLock::updateStats(ReadWriteLockStats
&stats
) const
56 stats
.readers
+= readers
;
59 stats
.writers
+= writers
;
66 /* Ipc::ReadWriteLockStats */
68 Ipc::ReadWriteLockStats::ReadWriteLockStats()
70 memset(this, 0, sizeof(*this));
74 Ipc::ReadWriteLockStats::dump(StoreEntry
&e
) const
76 storeAppendPrintf(&e
, "Available locks: %9d\n", count
);
81 storeAppendPrintf(&e
, "Reading: %9d %6.2f%%\n",
82 readable
, (100.0 * readable
/ count
));
83 storeAppendPrintf(&e
, "Writing: %9d %6.2f%%\n",
84 writeable
, (100.0 * writeable
/ count
));
85 storeAppendPrintf(&e
, "Idle: %9d %6.2f%%\n",
86 idle
, (100.0 * idle
/ count
));
88 if (readers
|| writers
) {
89 const int locked
= readers
+ writers
;
90 storeAppendPrintf(&e
, "Readers: %9d %6.2f%%\n",
91 readers
, (100.0 * readers
/ locked
));
92 storeAppendPrintf(&e
, "Writers: %9d %6.2f%%\n",
93 writers
, (100.0 * writers
/ locked
));