]> git.ipfire.org Git - thirdparty/squid.git/blob - src/base/AsyncCallList.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / base / AsyncCallList.h
1 /*
2 * Copyright (C) 1996-2023 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_BASE_ASYNCCALLLIST_H
10 #define SQUID_BASE_ASYNCCALLLIST_H
11
12 #include "base/forward.h"
13 #include "base/RefCount.h"
14
15 /// An efficient (but intrusive) AsyncCall storage preserving FIFO order.
16 /// A given AsyncCall object may reside in at most one such storage.
17 class AsyncCallList
18 {
19 public:
20 AsyncCallList() = default;
21 // prohibit copying: no AsyncCall should be present in two lists
22 AsyncCallList(const AsyncCallList &) = delete;
23 AsyncCallList &operator=(const AsyncCallList &) = delete;
24
25 /// stores the given async call
26 void add(const AsyncCallPointer &);
27
28 /// removes the earliest add()-ed call that is still stored (if any)
29 /// \returns the removed call (or nil)
30 /// \retval nil means the list stored no calls at extract() time
31 AsyncCallPointer extract();
32
33 /// the number of currently stored calls
34 size_t size() const { return length; }
35
36 private:
37 AsyncCallPointer head; ///< the earliest still-stored call (or nil)
38 AsyncCallPointer tail; ///< the latest still-stored call (or nil)
39 size_t length = 0; ///< \copydoc size()
40 };
41
42 #endif /* SQUID_BASE_ASYNCCALLLIST_H */
43