]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/ReadWriteLock.h
1 #ifndef SQUID_IPC_READ_WRITE_LOCK_H
2 #define SQUID_IPC_READ_WRITE_LOCK_H
4 #include "ipc/AtomicWord.h"
11 class ReadWriteLockStats
;
13 /// an atomic readers-writer or shared-exclusive lock suitable for maps/tables
17 // default constructor is OK because of shared memory zero-initialization
19 bool lockShared(); ///< lock for reading or return false
20 bool lockExclusive(); ///< lock for modification or return false
21 void unlockShared(); ///< undo successful sharedLock()
22 void unlockExclusive(); ///< undo successful exclusiveLock()
23 void switchExclusiveToShared(); ///< stop writing, start reading
25 /// adds approximate current stats to the supplied ones
26 void updateStats(ReadWriteLockStats
&stats
) const;
29 mutable Atomic::Word readers
; ///< number of users trying to read
30 Atomic::Word writers
; ///< number of writers trying to modify protected data
34 /// approximate stats of a set of ReadWriteLocks
35 class ReadWriteLockStats
40 void dump(StoreEntry
&e
) const;
42 int count
; ///< the total number of locks
43 int readable
; ///< number of locks locked for reading
44 int writeable
; ///< number of locks locked for writing
45 int idle
; ///< number of unlocked locks
46 int readers
; ///< sum of lock.readers
47 int writers
; ///< sum of lock.writers
52 #endif /* SQUID_IPC_READ_WRITE_LOCK_H */