]>
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 unsigned int pageSize
):
25 pageIndex(PageIndexId(id
), capacity
),
28 shm
.create(sizeof(Shared
) + pageSize
*capacity
);
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::get(PageId
&page
)
44 if (pageIndex
.pop(page
.number
)) {
45 page
.pool
= shared
->theId
;
52 Ipc::Mem::PagePool::put(PageId
&page
)
54 Must(pageIdIsValid(page
));
55 pageIndex
.push(page
.number
);
60 Ipc::Mem::PagePool::pagePointer(const PageId
&page
)
62 Must(pageIdIsValid(page
));
63 return shared
->theBuf
+ shared
->thePageSize
* (page
.number
- 1);
67 Ipc::Mem::PagePool::pageIdIsValid(const PageId
&page
) const
69 return page
.pool
== shared
->theId
&&
70 0 < page
.number
&& page
.number
<= shared
->theCapacity
;
74 // Ipc::Mem::PagePool::Shared
76 static unsigned int LastPagePoolId
= 0;
78 Ipc::Mem::PagePool::Shared::Shared(const unsigned int aCapacity
, const unsigned int aPageSize
):
79 theId(++LastPagePoolId
), theCapacity(aCapacity
), thePageSize(aPageSize
)
81 if (LastPagePoolId
+ 1 == 0)
82 ++LastPagePoolId
; // skip zero pool id