]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.cc
2 * Copyright (C) 1996-2017 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 id
, const unsigned int capacity
, const size_t pageSize
)
21 static uint32_t LastPagePoolId
= 0;
22 if (++LastPagePoolId
== 0)
23 ++LastPagePoolId
; // skip zero pool id
24 return shm_new(PageStack
)(id
, LastPagePoolId
, capacity
, pageSize
);
27 Ipc::Mem::PagePool::PagePool(const char *const id
):
28 pageIndex(shm_old(PageStack
)(id
)),
29 theLevels(reinterpret_cast<Levels_t
*>(
30 reinterpret_cast<char *>(pageIndex
.getRaw()) +
31 pageIndex
->stackSize())),
32 theBuf(reinterpret_cast<char *>(theLevels
+ PageId::maxPurpose
))
37 Ipc::Mem::PagePool::level(const int purpose
) const
39 Must(0 <= purpose
&& purpose
< PageId::maxPurpose
);
40 return theLevels
[purpose
];
44 Ipc::Mem::PagePool::get(const PageId::Purpose purpose
, PageId
&page
)
46 Must(0 <= purpose
&& purpose
< PageId::maxPurpose
);
47 if (pageIndex
->pop(page
)) {
48 page
.purpose
= purpose
;
56 Ipc::Mem::PagePool::put(PageId
&page
)
61 Must(0 <= page
.purpose
&& page
.purpose
< PageId::maxPurpose
);
62 --theLevels
[page
.purpose
];
63 page
.purpose
= PageId::maxPurpose
;
64 return pageIndex
->push(page
);
68 Ipc::Mem::PagePool::pagePointer(const PageId
&page
)
70 Must(pageIndex
->pageIdIsValid(page
));
71 return theBuf
+ pageSize() * (page
.number
- 1);