]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.cc
187cc712061fc380d496c27fa846e30e33ebe1a9
4 * DEBUG: section 54 Interprocess Communication
9 #include "base/TextException.h"
10 #include "ipc/mem/Page.h"
11 #include "ipc/mem/PagePool.h"
16 Ipc::Mem::PagePool::Owner
*
17 Ipc::Mem::PagePool::Init(const char *const id
, const unsigned int capacity
, const size_t pageSize
)
19 static uint32_t LastPagePoolId
= 0;
20 if (++LastPagePoolId
== 0)
21 ++LastPagePoolId
; // skip zero pool id
22 return shm_new(PageStack
)(id
, LastPagePoolId
, capacity
, pageSize
);
25 Ipc::Mem::PagePool::PagePool(const char *const id
):
26 pageIndex(shm_old(PageStack
)(id
)),
27 theLevels(reinterpret_cast<Atomic::Word
*>(
28 reinterpret_cast<char *>(pageIndex
.getRaw()) +
29 pageIndex
->stackSize())),
30 theBuf(reinterpret_cast<char *>(theLevels
+ PageId::maxPurpose
))
35 Ipc::Mem::PagePool::level(const int purpose
) const
37 Must(0 <= purpose
&& purpose
< PageId::maxPurpose
);
38 return theLevels
[purpose
];
42 Ipc::Mem::PagePool::get(const PageId::Purpose purpose
, PageId
&page
)
44 Must(0 <= purpose
&& purpose
< PageId::maxPurpose
);
45 if (pageIndex
->pop(page
)) {
46 page
.purpose
= purpose
;
54 Ipc::Mem::PagePool::put(PageId
&page
)
59 Must(0 <= page
.purpose
&& page
.purpose
< PageId::maxPurpose
);
60 --theLevels
[page
.purpose
];
61 page
.purpose
= PageId::maxPurpose
;
62 return pageIndex
->push(page
);
66 Ipc::Mem::PagePool::pagePointer(const PageId
&page
)
68 Must(pageIndex
->pageIdIsValid(page
));
69 return theBuf
+ pageSize() * (page
.number
- 1);