]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.h
6 #ifndef SQUID_IPC_MEM_PAGE_POOL_H
7 #define SQUID_IPC_MEM_PAGE_POOL_H
9 #include "ipc/mem/PageStack.h"
10 #include "ipc/mem/Segment.h"
18 /// Atomic container of shared memory pages. Implemented using a collection of
19 /// Segments, each with a PageStack index of free pages. All pools must be
20 /// created by a single process.
23 /// creates a new shared page pool that can hold up to capacity pages of pageSize size
24 PagePool(const String
&id
, const unsigned int capacity
, const size_t pageSize
);
25 /// attaches to the identified shared page pool
26 PagePool(const String
&id
);
27 /// unlinks shared memory segments
28 static void Unlink(const String
&id
);
30 unsigned int capacity() const { return shared
->theCapacity
; }
31 /// lower bound for the number of free pages
32 unsigned int size() const { return pageIndex
.size(); }
33 size_t pageSize() const { return shared
->thePageSize
; }
35 /// sets page ID and returns true unless no free pages are found
36 bool get(PageId
&page
);
37 /// makes identified page available as a free page to future get() callers
38 void put(PageId
&page
);
39 /// converts page handler into a temporary writeable shared memory pointer
40 void *pagePointer(const PageId
&page
);
43 inline bool pageIdIsValid(const PageId
&page
) const;
46 Shared(const unsigned int aCapacity
, const size_t aPageSize
);
48 /// total shared memory size required to share
49 static off_t
MemSize(const unsigned int capacity
, const size_t pageSize
);
51 const unsigned int theId
; ///< pool id
52 const unsigned int theCapacity
; ///< number of pages in the pool
53 const size_t thePageSize
; ///< page size
55 // TODO: add padding to make pages system page-aligned?
56 char theBuf
[]; ///< pages storage
59 PageStack pageIndex
; ///< free pages index
60 Segment shm
; ///< shared memory segment to store metadata (and pages)
61 Shared
*shared
; ///< our metadata and page storage, shared among all pool users
68 #endif // SQUID_IPC_MEM_PAGE_POOL_H