]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.h
Merged from parent (trunk r11623, v3.2.0.10+).
[thirdparty/squid.git] / src / ipc / mem / PagePool.h
1 /*
2 * $Id$
3 *
4 */
5
6 #ifndef SQUID_IPC_MEM_PAGE_POOL_H
7 #define SQUID_IPC_MEM_PAGE_POOL_H
8
9 #include "ipc/mem/Page.h"
10 #include "ipc/mem/PageStack.h"
11 #include "ipc/mem/Pointer.h"
12
13 namespace Ipc {
14
15 namespace Mem {
16
17 /// Atomic container of shared memory pages. Implemented using a collection of
18 /// Segments, each with a PageStack index of free pages. All pools must be
19 /// created by a single process.
20 class PagePool {
21 public:
22 typedef Ipc::Mem::Owner<PageStack> Owner;
23
24 static Owner *Init(const char *const id, const unsigned int capacity, const size_t pageSize);
25
26 PagePool(const char *const id);
27
28 unsigned int capacity() const { return pageIndex->capacity(); }
29 size_t pageSize() const { return pageIndex->pageSize(); }
30 /// lower bound for the number of free pages
31 unsigned int size() const { return pageIndex->size(); }
32 /// approximate number of shared memory pages used now
33 size_t level() const { return capacity() - size(); }
34 /// approximate number of shared memory pages used now for given purpose
35 size_t level(const int purpose) const;
36
37 /// sets page ID and returns true unless no free pages are found
38 bool get(const PageId::Purpose purpose, PageId &page);
39 /// makes identified page available as a free page to future get() callers
40 void put(PageId &page);
41 /// converts page handler into a temporary writeable shared memory pointer
42 char *pagePointer(const PageId &page);
43
44 private:
45 Ipc::Mem::Pointer<PageStack> pageIndex; ///< free pages index
46 /// number of shared memory pages used now for each purpose
47 AtomicWord *const theLevels;
48 char *const theBuf; ///< pages storage
49 };
50
51 } // namespace Mem
52
53 } // namespace Ipc
54
55 #endif // SQUID_IPC_MEM_PAGE_POOL_H