ReadWriteLock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
14 class StoreEntry;
15 
16 namespace Ipc
17 {
18 
19 class ReadWriteLockStats;
20 
26 {
27 public:
29  {}
30 
31  bool lockShared();
32  bool lockExclusive();
33  bool lockHeaders();
34  void unlockShared();
35  void unlockExclusive();
36  void unlockHeaders();
38 
39  void startAppending();
40 
43 
44 public:
45  mutable std::atomic<uint32_t> readers;
46  std::atomic<bool> writing;
47  std::atomic<bool> appending;
48  std::atomic_flag updating;
49 
50 private:
51  mutable std::atomic<uint32_t> readLevel;
52  std::atomic<uint32_t> writeLevel;
53 };
54 
57 {
58 public:
60 
61  void dump(StoreEntry &e) const;
62 
63  int count;
64  int readable;
65  int writeable;
66  int idle;
67  int readers;
68  int writers;
69  int appenders;
70 };
71 
75 void AssertFlagIsSet(std::atomic_flag &flag);
76 
77 } // namespace Ipc
78 
79 #endif /* SQUID_IPC_READ_WRITE_LOCK_H */
80 
int writers
sum of lock.writers
Definition: ReadWriteLock.h:68
void unlockHeaders()
undo successful lockHeaders()
class Ping::pingStats_ stats
int idle
number of unlocked locks
Definition: ReadWriteLock.h:66
approximate stats of a set of ReadWriteLocks
Definition: ReadWriteLock.h:56
bool lockHeaders()
lock for [readable] metadata update or return false
void switchExclusiveToShared()
stop writing, start reading
std::atomic< uint32_t > readLevel
number of users reading (or trying to)
Definition: ReadWriteLock.h:51
int writeable
number of locks locked for writing
Definition: ReadWriteLock.h:65
int readers
sum of lock.readers
Definition: ReadWriteLock.h:67
bool lockExclusive()
lock for modification or return false
void unlockExclusive()
undo successful exclusiveLock()
int count
the total number of locks
Definition: ReadWriteLock.h:63
bool lockShared()
lock for reading or return false
void AssertFlagIsSet(std::atomic_flag &flag)
std::atomic< bool > appending
the writer has promised to only append
Definition: ReadWriteLock.h:47
void unlockShared()
undo successful sharedLock()
std::atomic_flag updating
a reader is updating metadata/headers
Definition: ReadWriteLock.h:48
void updateStats(ReadWriteLockStats &stats) const
adds approximate current stats to the supplied ones
std::atomic< uint32_t > readers
number of reading users
Definition: ReadWriteLock.h:45
std::atomic< bool > writing
there is a writing user (there can be at most 1)
Definition: ReadWriteLock.h:46
void startAppending()
writer keeps its lock but also allows reading
int appenders
number of appending writers
Definition: ReadWriteLock.h:69
std::atomic< uint32_t > writeLevel
number of users writing (or trying to write)
Definition: ReadWriteLock.h:52
int readable
number of locks locked for reading
Definition: ReadWriteLock.h:64
#define false
Definition: GnuRegex.c:233
void dump(StoreEntry &e) const

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors