1 /*
2  * Copyright (C) 1996-2021 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_IPC_MEM_PAGES_H
10 #define SQUID_IPC_MEM_PAGES_H
11 
12 #include "ipc/mem/Page.h"
13 
14 namespace Ipc
15 {
16 
17 namespace Mem
18 {
19 
20 /* Single page manipulation */
21 
22 /// sets page ID and returns true unless no free pages are found
23 bool GetPage(const PageId::Purpose purpose, PageId &page);
24 
25 /// makes identified page available as a free page to future GetPage() callers
26 void PutPage(PageId &page);
27 
28 /// converts page handler into a temporary writeable shared memory pointer
29 char *PagePointer(const PageId &page);
30 
31 /* Limits and statistics */
32 
33 /// the total number of shared memory pages that can be in use at any time
34 size_t PageLimit();
35 
36 /// the total number of shared memory pages that can be in use at any
37 /// time for given purpose
38 size_t PageLimit(const int purpose);
39 
40 /// approximate total number of shared memory pages used now
41 size_t PageLevel();
42 
43 /// approximate total number of shared memory pages used now for given purpose
44 size_t PageLevel(const int purpose);
45 
46 /// approximate total number of shared memory pages we can allocate now
PagesAvailable()47 inline size_t PagesAvailable() { return PageLimit() - PageLevel(); }
48 
49 /// approximate total number of shared memory pages we can allocate
50 /// now for given purpose
PagesAvailable(const int purpose)51 inline size_t PagesAvailable(const int purpose) { return PageLimit(purpose) - PageLevel(purpose); }
52 
53 /// returns page size in bytes; all pages are assumed to be the same size
54 size_t PageSize();
55 
56 /// claim the need for a number of pages for a given purpose
57 void NotePageNeed(const int purpose, const int count);
58 
59 } // namespace Mem
60 
61 } // namespace Ipc
62 
63 #endif // SQUID_IPC_MEM_PAGES_H
64 
65