]>
Commit | Line | Data |
---|---|---|
3e0ddf16 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
3e0ddf16 | 3 | * |
bbc27441 AJ |
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 | ||
bbc27441 AJ |
9 | /* DEBUG: section 54 Interprocess Communication */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
56f8aa50 DK |
12 | #include "base/TextException.h" |
13 | #include "ipc/mem/Page.h" | |
3e0ddf16 AR |
14 | #include "ipc/mem/PagePool.h" |
15 | ||
56f8aa50 DK |
16 | // Ipc::Mem::PagePool |
17 | ||
68353d5a | 18 | Ipc::Mem::PagePool::Owner * |
1fe7f70f | 19 | Ipc::Mem::PagePool::Init(const char *const shmId, const Ipc::Mem::PoolId stackId, const unsigned int capacity, const size_t pageSize) |
56f8aa50 | 20 | { |
f670688c EB |
21 | PageStack::Config config; |
22 | config.poolId = stackId; | |
23 | config.pageSize = pageSize; // the pages are stored in Ipc::Mem::Pages | |
24 | config.capacity = capacity; | |
25 | config.createFull = true; // all pages are initially available | |
26 | return shm_new(PageStack)(shmId, config); | |
56f8aa50 DK |
27 | } |
28 | ||
68353d5a | 29 | Ipc::Mem::PagePool::PagePool(const char *const id): |
f53969cc | 30 | pageIndex(shm_old(PageStack)(id)), |
98b3fdc4 | 31 | theLevels(reinterpret_cast<Levels_t *>( |
f53969cc | 32 | reinterpret_cast<char *>(pageIndex.getRaw()) + |
2a10e977 | 33 | pageIndex->stackSize() + pageIndex->levelsPaddingSize())), |
f53969cc | 34 | theBuf(reinterpret_cast<char *>(theLevels + PageId::maxPurpose)) |
56f8aa50 | 35 | { |
551f8a18 DK |
36 | } |
37 | ||
38 | size_t | |
39 | Ipc::Mem::PagePool::level(const int purpose) const | |
40 | { | |
41 | Must(0 <= purpose && purpose < PageId::maxPurpose); | |
42 | return theLevels[purpose]; | |
43 | } | |
44 | ||
45 | bool | |
46 | Ipc::Mem::PagePool::get(const PageId::Purpose purpose, PageId &page) | |
47 | { | |
48 | Must(0 <= purpose && purpose < PageId::maxPurpose); | |
49 | if (pageIndex->pop(page)) { | |
50 | page.purpose = purpose; | |
51 | ++theLevels[purpose]; | |
52 | return true; | |
53 | } | |
54 | return false; | |
55 | } | |
56 | ||
57 | void | |
58 | Ipc::Mem::PagePool::put(PageId &page) | |
59 | { | |
60 | if (!page) | |
61 | return; | |
62 | ||
63 | Must(0 <= page.purpose && page.purpose < PageId::maxPurpose); | |
64 | --theLevels[page.purpose]; | |
65 | page.purpose = PageId::maxPurpose; | |
66 | return pageIndex->push(page); | |
56f8aa50 DK |
67 | } |
68 | ||
8ed94021 | 69 | char * |
56f8aa50 DK |
70 | Ipc::Mem::PagePool::pagePointer(const PageId &page) |
71 | { | |
68353d5a DK |
72 | Must(pageIndex->pageIdIsValid(page)); |
73 | return theBuf + pageSize() * (page.number - 1); | |
39c0d994 | 74 | } |
f53969cc | 75 |