]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ipc/mem/Pages.cc
Fixed raw page buffer type.
[thirdparty/squid.git] / src / ipc / mem / Pages.cc
CommitLineData
3e0ddf16
AR
1/*
2 * $Id$
3 *
4 * DEBUG: section 54 Interprocess Communication
5 *
6 */
7
8#include "config.h"
56f8aa50
DK
9#include "base/TextException.h"
10#include "ipc/mem/PagePool.h"
3e0ddf16 11#include "ipc/mem/Pages.h"
56f8aa50
DK
12#include "structs.h"
13#include "SwapDir.h"
3e0ddf16 14
56f8aa50 15// Uses a single PagePool instance, for now.
3e0ddf16 16// Eventually, we may have pools dedicated to memory caching, disk I/O, etc.
56f8aa50
DK
17
18// TODO: make pool id more unique so it does not conflict with other Squids?
19static const String PagePoolId = "squid-page-pool";
20static Ipc::Mem::PagePool *ThePagePool = 0;
21
22// XXX: temporary function until we have a better page size handling
23static unsigned int
24calculatePageSize()
25{
26 unsigned int max_objsize = 0;
27 for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
28 const SwapDir *const sd = dynamic_cast<SwapDir *>(INDEXSD(i));
29 if (sd->max_objsize > max_objsize)
30 max_objsize = sd->max_objsize;
31 }
32 return max_objsize;
33}
34
35void
36Ipc::Mem::Init()
37{
38 Must(!ThePagePool);
39 // XXX: pool capacity and page size should be configurable/meaningful
40 ThePagePool = new PagePool(PagePoolId, 1024, calculatePageSize());
41}
42
43void
44Ipc::Mem::Attach()
45{
46 Must(!ThePagePool);
47 // TODO: make pool id more unique so it does not conflict with other Squid instances?
48 ThePagePool = new PagePool(PagePoolId);
49}
50
51bool
52Ipc::Mem::GetPage(PageId &page)
53{
54 Must(ThePagePool);
55 return ThePagePool->get(page);
56}
57
58void
59Ipc::Mem::PutPage(PageId &page)
60{
61 Must(ThePagePool);
62 ThePagePool->put(page);
63}
64
65void *
66Ipc::Mem::PagePointer(const PageId &page)
67{
68 Must(ThePagePool);
69 return ThePagePool->pagePointer(page);
70}