PagePool.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 54 Interprocess Communication */
10 
11 #include "squid.h"
12 #include "base/TextException.h"
13 #include "ipc/mem/Page.h"
14 #include "ipc/mem/PagePool.h"
15 
16 // Ipc::Mem::PagePool
17 
19 Ipc::Mem::PagePool::Init(const char *const id, const unsigned int capacity, const size_t pageSize)
20 {
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);
25 }
26 
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))
33 {
34 }
35 
36 size_t
37 Ipc::Mem::PagePool::level(const int purpose) const
38 {
39  Must(0 <= purpose && purpose < PageId::maxPurpose);
40  return theLevels[purpose];
41 }
42 
43 bool
45 {
46  Must(0 <= purpose && purpose < PageId::maxPurpose);
47  if (pageIndex->pop(page)) {
48  page.purpose = purpose;
49  ++theLevels[purpose];
50  return true;
51  }
52  return false;
53 }
54 
55 void
57 {
58  if (!page)
59  return;
60 
61  Must(0 <= page.purpose && page.purpose < PageId::maxPurpose);
62  --theLevels[page.purpose];
64  return pageIndex->push(page);
65 }
66 
67 char *
69 {
70  Must(pageIndex->pageIdIsValid(page));
71  return theBuf + pageSize() * (page.number - 1);
72 }
73 
size_t pageSize() const
Definition: PagePool.h:35
#define shm_old(Class)
Definition: Pointer.h:180
unsigned int capacity() const
Definition: PagePool.h:34
static Owner * Init(const char *const id, const unsigned int capacity, const size_t pageSize)
Definition: PagePool.cc:19
bool get(const PageId::Purpose purpose, PageId &page)
sets page ID and returns true unless no free pages are found
Definition: PagePool.cc:44
std::atomic< size_t > Levels_t
Definition: PagePool.h:52
void put(PageId &page)
makes identified page available as a free page to future get() callers
Definition: PagePool.cc:56
uint32_t number
page number within the segment
Definition: Page.h:35
char * pagePointer(const PageId &page)
converts page handler into a temporary writeable shared memory pointer
Definition: PagePool.cc:68
#define shm_new(Class)
Definition: Pointer.h:179
#define Must(cond)
Definition: TextException.h:89
Purpose purpose
page purpose
Definition: Page.h:38
Shared memory page identifier, address, or handler.
Definition: Page.h:21
PagePool(const char *const id)
Definition: PagePool.cc:27
size_t level() const
approximate number of shared memory pages used now
Definition: PagePool.h:39

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors