]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.h
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_IPC_MEM_PAGE_POOL_H
10 #define SQUID_IPC_MEM_PAGE_POOL_H
12 #include "ipc/mem/Page.h"
13 #include "ipc/mem/PageStack.h"
14 #include "ipc/mem/Pointer.h"
22 /// Atomic container of shared memory pages. Implemented using a collection of
23 /// Segments, each with a PageStack index of free pages. All pools must be
24 /// created by a single process.
28 typedef Ipc::Mem::Owner
<PageStack
> Owner
;
30 static Owner
*Init(const char *const id
, const unsigned int capacity
, const size_t pageSize
);
32 PagePool(const char *const id
);
34 unsigned int capacity() const { return pageIndex
->capacity(); }
35 size_t pageSize() const { return pageIndex
->pageSize(); }
36 /// lower bound for the number of free pages
37 unsigned int size() const { return pageIndex
->size(); }
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;
43 /// sets page ID and returns true unless no free pages are found
44 bool get(const PageId::Purpose purpose
, PageId
&page
);
45 /// makes identified page available as a free page to future get() callers
46 void put(PageId
&page
);
47 /// converts page handler into a temporary writeable shared memory pointer
48 char *pagePointer(const PageId
&page
);
51 Ipc::Mem::Pointer
<PageStack
> pageIndex
; ///< free pages index
52 /// number of shared memory pages used now for each purpose
53 Atomic::Word
*const theLevels
;
54 char *const theBuf
; ///< pages storage
61 #endif // SQUID_IPC_MEM_PAGE_POOL_H