ReadWriteLock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #ifndef SQUID_IPC_READ_WRITE_LOCK_H
10 #define SQUID_IPC_READ_WRITE_LOCK_H
11 
12 #include <atomic>
13 #include <iosfwd>
14 
15 class StoreEntry;
16 
17 namespace Ipc
18 {
19 
20 class ReadWriteLockStats;
21 
27 {
28 public:
30  {}
31 
32  bool lockShared();
33  bool lockExclusive();
34  bool lockHeaders();
35  void unlockShared();
36  void unlockExclusive();
37  void unlockHeaders();
42 
43  void startAppending();
44 
47 
48 public:
49  mutable std::atomic<uint32_t> readers;
50  std::atomic<bool> writing;
51  std::atomic<bool> appending;
52  std::atomic_flag updating;
53 
54 private:
55  bool finalizeExclusive();
56 
57  mutable std::atomic<uint32_t> readLevel;
58  std::atomic<uint32_t> writeLevel;
59 };
60 
62 std::ostream &operator <<(std::ostream &os, const Ipc::ReadWriteLock &);
63 
66 {
67 public:
69 
70  void dump(StoreEntry &e) const;
71 
72  int count;
73  int readable;
74  int writeable;
75  int idle;
76  int readers;
77  int writers;
78  int appenders;
79 };
80 
84 void AssertFlagIsSet(std::atomic_flag &flag);
85 
86 } // namespace Ipc
87 
88 #endif /* SQUID_IPC_READ_WRITE_LOCK_H */
89 
class Ping::pingStats_ stats
approximate stats of a set of ReadWriteLocks
Definition: ReadWriteLock.h:66
std::atomic< bool > writing
there is a writing user (there can be at most 1)
Definition: ReadWriteLock.h:50
bool lockShared()
lock for reading or return false
bool unlockSharedAndSwitchToExclusive()
void updateStats(ReadWriteLockStats &stats) const
adds approximate current stats to the supplied ones
bool lockExclusive()
lock for modification or return false
int writers
sum of lock.writers
Definition: ReadWriteLock.h:77
std::atomic< bool > appending
the writer has promised to only append
Definition: ReadWriteLock.h:51
std::atomic_flag updating
a reader is updating metadata/headers
Definition: ReadWriteLock.h:52
void unlockShared()
undo successful sharedLock()
std::atomic< uint32_t > readers
number of reading users
Definition: ReadWriteLock.h:49
void unlockExclusive()
undo successful exclusiveLock()
int readers
sum of lock.readers
Definition: ReadWriteLock.h:76
bool lockHeaders()
lock for [readable] metadata update or return false
int appenders
number of appending writers
Definition: ReadWriteLock.h:78
void dump(StoreEntry &e) const
int idle
number of unlocked locks
Definition: ReadWriteLock.h:75
void unlockHeaders()
undo successful lockHeaders()
void AssertFlagIsSet(std::atomic_flag &flag)
std::atomic< uint32_t > writeLevel
number of users writing (or trying to write)
Definition: ReadWriteLock.h:58
int writeable
number of locks locked for writing
Definition: ReadWriteLock.h:74
std::ostream & operator<<(std::ostream &os, const QuestionerId &qid)
Definition: QuestionerId.h:63
int readable
number of locks locked for reading
Definition: ReadWriteLock.h:73
void switchExclusiveToShared()
#define false
Definition: GnuRegex.c:233
void startAppending()
writer keeps its lock but also allows reading
std::atomic< uint32_t > readLevel
number of users reading (or trying to)
Definition: ReadWriteLock.h:57
int count
the total number of locks
Definition: ReadWriteLock.h:72
Definition: IpcIoFile.h:24

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors