]>
Commit | Line | Data |
---|---|---|
3e0ddf16 | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 The Squid Software Foundation and contributors |
bbc27441 AJ |
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. | |
3e0ddf16 AR |
7 | */ |
8 | ||
9 | #ifndef SQUID_IPC_MEM_PAGE_POOL_H | |
10 | #define SQUID_IPC_MEM_PAGE_POOL_H | |
11 | ||
551f8a18 | 12 | #include "ipc/mem/Page.h" |
56f8aa50 | 13 | #include "ipc/mem/PageStack.h" |
68353d5a | 14 | #include "ipc/mem/Pointer.h" |
3e0ddf16 | 15 | |
9199139f AR |
16 | namespace Ipc |
17 | { | |
3e0ddf16 | 18 | |
9199139f AR |
19 | namespace Mem |
20 | { | |
3e0ddf16 AR |
21 | |
22 | /// Atomic container of shared memory pages. Implemented using a collection of | |
56f8aa50 DK |
23 | /// Segments, each with a PageStack index of free pages. All pools must be |
24 | /// created by a single process. | |
9199139f AR |
25 | class PagePool |
26 | { | |
3e0ddf16 | 27 | public: |
68353d5a DK |
28 | typedef Ipc::Mem::Owner<PageStack> Owner; |
29 | ||
1fe7f70f | 30 | static Owner *Init(const char *const shmId, const Ipc::Mem::PoolId stackId, const unsigned int capacity, const size_t pageSize); |
3e0ddf16 | 31 | |
68353d5a DK |
32 | PagePool(const char *const id); |
33 | ||
34 | unsigned int capacity() const { return pageIndex->capacity(); } | |
35 | size_t pageSize() const { return pageIndex->pageSize(); } | |
b940ff87 | 36 | /// lower bound for the number of free pages |
68353d5a | 37 | unsigned int size() const { return pageIndex->size(); } |
551f8a18 DK |
38 | /// approximate number of shared memory pages used now |
39 | size_t level() const { return capacity() - size(); } | |
40 | /// approximate number of shared memory pages used now for given purpose | |
41 | size_t level(const int purpose) const; | |
56f8aa50 | 42 | |
3e0ddf16 | 43 | /// sets page ID and returns true unless no free pages are found |
551f8a18 | 44 | bool get(const PageId::Purpose purpose, PageId &page); |
3e0ddf16 | 45 | /// makes identified page available as a free page to future get() callers |
551f8a18 | 46 | void put(PageId &page); |
56f8aa50 | 47 | /// converts page handler into a temporary writeable shared memory pointer |
8ed94021 | 48 | char *pagePointer(const PageId &page); |
3e0ddf16 AR |
49 | |
50 | private: | |
68353d5a | 51 | Ipc::Mem::Pointer<PageStack> pageIndex; ///< free pages index |
2a10e977 | 52 | using Levels_t = PageStack::Levels_t; |
53 | ||
551f8a18 | 54 | /// number of shared memory pages used now for each purpose |
98b3fdc4 | 55 | Levels_t * const theLevels; |
551f8a18 | 56 | char *const theBuf; ///< pages storage |
3e0ddf16 AR |
57 | }; |
58 | ||
59 | } // namespace Mem | |
60 | ||
61 | } // namespace Ipc | |
62 | ||
63 | #endif // SQUID_IPC_MEM_PAGE_POOL_H | |
f53969cc | 64 |