]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ipc/mem/PagePool.cc
4 * DEBUG: section 54 Interprocess Communication
9 #include "base/TextException.h"
10 #include "ipc/mem/Page.h"
11 #include "ipc/mem/PagePool.h"
15 PageIndexId(String id
)
24 Ipc::Mem::PagePool::PagePool(const String
&id
, const unsigned int capacity
, const size_t pageSize
):
25 pageIndex(PageIndexId(id
), capacity
),
28 shm
.create(Shared::MemSize(capacity
, pageSize
));
30 shared
= new (shm
.mem()) Shared(capacity
, pageSize
);
33 Ipc::Mem::PagePool::PagePool(const String
&id
):
34 pageIndex(PageIndexId(id
)), shm(id
.termedBuf())
37 shared
= reinterpret_cast<Shared
*>(shm
.mem());
42 Ipc::Mem::PagePool::Unlink(const String
&id
)
44 PageStack::Unlink(PageIndexId(id
));
45 Segment::Unlink(id
.termedBuf());
49 Ipc::Mem::PagePool::get(PageId
&page
)
51 if (pageIndex
.pop(page
.number
)) {
52 page
.pool
= shared
->theId
;
59 Ipc::Mem::PagePool::put(PageId
&page
)
61 Must(pageIdIsValid(page
));
62 pageIndex
.push(page
.number
);
67 Ipc::Mem::PagePool::pagePointer(const PageId
&page
)
69 Must(pageIdIsValid(page
));
70 return shared
->theBuf
+ shared
->thePageSize
* (page
.number
- 1);
74 Ipc::Mem::PagePool::pageIdIsValid(const PageId
&page
) const
76 return page
.pool
== shared
->theId
&&
77 0 < page
.number
&& page
.number
<= shared
->theCapacity
;
81 // Ipc::Mem::PagePool::Shared
83 static unsigned int LastPagePoolId
= 0;
85 Ipc::Mem::PagePool::Shared::Shared(const unsigned int aCapacity
, size_t aPageSize
):
86 theId(++LastPagePoolId
), theCapacity(aCapacity
), thePageSize(aPageSize
)
88 if (LastPagePoolId
+ 1 == 0)
89 ++LastPagePoolId
; // skip zero pool id
93 Ipc::Mem::PagePool::Shared::MemSize(const unsigned int capacity
, const size_t pageSize
)
95 return static_cast<off_t
>(sizeof(Shared
)) +
96 static_cast<off_t
>(pageSize
) * capacity
;