]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/ReadWriteLock.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 54 Interprocess Communication */
12 #include "ipc/ReadWriteLock.h"
16 Ipc::ReadWriteLock::lockShared()
18 ++readLevel
; // this locks "new" writers out
19 if (!writeLevel
|| appending
) { // nobody is writing, or sharing is OK
28 Ipc::ReadWriteLock::lockExclusive()
30 if (!writeLevel
++) { // we are the first writer + lock "new" readers out
31 if (!readLevel
) { // no old readers and nobody is becoming one
41 Ipc::ReadWriteLock::unlockShared()
49 Ipc::ReadWriteLock::unlockExclusive()
58 Ipc::ReadWriteLock::switchExclusiveToShared()
61 ++readLevel
; // must be done before we release exclusive control
67 Ipc::ReadWriteLock::startAppending()
74 Ipc::ReadWriteLock::updateStats(ReadWriteLockStats
&stats
) const
78 stats
.readers
+= readers
;
82 stats
.appenders
+= appending
;
89 /* Ipc::ReadWriteLockStats */
91 Ipc::ReadWriteLockStats::ReadWriteLockStats()
93 memset(this, 0, sizeof(*this));
97 Ipc::ReadWriteLockStats::dump(StoreEntry
&e
) const
99 storeAppendPrintf(&e
, "Available locks: %9d\n", count
);
104 storeAppendPrintf(&e
, "Reading: %9d %6.2f%%\n",
105 readable
, (100.0 * readable
/ count
));
106 storeAppendPrintf(&e
, "Writing: %9d %6.2f%%\n",
107 writeable
, (100.0 * writeable
/ count
));
108 storeAppendPrintf(&e
, "Idle: %9d %6.2f%%\n",
109 idle
, (100.0 * idle
/ count
));
111 if (readers
|| writers
) {
112 const int locked
= readers
+ writers
;
113 storeAppendPrintf(&e
, "Readers: %9d %6.2f%%\n",
114 readers
, (100.0 * readers
/ locked
));
115 const double appPerc
= writers
? (100.0 * appenders
/ writers
) : 0.0;
116 storeAppendPrintf(&e
, "Writers: %9d %6.2f%% including Appenders: %9d %6.2f%%\n",
117 writers
, (100.0 * writers
/ locked
),