]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.cc
3dd4dbd84d40255a4f72d808e34970ccc39f9580
2 * Copyright (C) 1996-2025 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 /* DEBUG: section 54 Interprocess Communication */
12 #include "base/TextException.h"
13 #include "ipc/mem/Page.h"
14 #include "ipc/mem/PagePool.h"
18 Ipc::Mem::PagePool::Owner
*
19 Ipc::Mem::PagePool::Init(const char *const shmId
, const Ipc::Mem::PoolId stackId
, const unsigned int capacity
, const size_t pageSize
)
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
);
29 Ipc::Mem::PagePool::PagePool(const char *const id
):
30 pageIndex(shm_old(PageStack
)(id
)),
31 theLevels(reinterpret_cast<Levels_t
*>(
32 reinterpret_cast<char *>(pageIndex
.getRaw()) +
33 pageIndex
->stackSize() + pageIndex
->levelsPaddingSize())),
34 theBuf(reinterpret_cast<char *>(theLevels
+ PageId::maxPurpose
))
39 Ipc::Mem::PagePool::level(const int purpose
) const
41 Must(0 <= purpose
&& purpose
< PageId::maxPurpose
);
42 return theLevels
[purpose
];
46 Ipc::Mem::PagePool::get(const PageId::Purpose purpose
, PageId
&page
)
48 Must(0 <= purpose
&& purpose
< PageId::maxPurpose
);
49 if (pageIndex
->pop(page
)) {
50 page
.purpose
= purpose
;
58 Ipc::Mem::PagePool::put(PageId
&page
)
63 Must(0 <= page
.purpose
&& page
.purpose
< PageId::maxPurpose
);
64 --theLevels
[page
.purpose
];
65 page
.purpose
= PageId::maxPurpose
;
66 return pageIndex
->push(page
);
70 Ipc::Mem::PagePool::pagePointer(const PageId
&page
)
72 Must(pageIndex
->pageIdIsValid(page
));
73 return theBuf
+ pageSize() * (page
.number
- 1);