mem_node.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 19 Store Memory Primitives */
10 
11 #include "squid.h"
12 #include "mem/Pool.h"
13 #include "mem_node.h"
14 
15 static ptrdiff_t makeMemNodeDataOffset();
16 
18 
19 /*
20  * Calculate the offset between the start of a mem_node and
21  * its 'data' member
22  */
23 static ptrdiff_t
25 {
26  mem_node *p = 0L;
27  return ptrdiff_t(&p->data);
28 }
29 
30 /*
31  * This is the callback when storeIOWrite() is done. We need to
32  * clear the write_pending flag for the mem_node. First we have
33  * to calculate the start of the mem_node based on the character
34  * buffer that we wrote. ick.
35  */
36 void
38 {
39  mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
41  n->write_pending = false;
42 }
43 
44 mem_node::mem_node(int64_t offset) :
45  nodeBuffer(0,offset,data),
46  write_pending(false)
47 {
48  *data = 0;
49 }
50 
52 {}
53 
54 size_t
56 {
57  return Pool().inUseCount();
58 }
59 
60 size_t
62 {
63  return InUseCount() * SM_PAGE_SIZE;
64 }
65 
66 int64_t
68 {
69  assert (nodeBuffer.offset >= 0);
70  return nodeBuffer.offset;
71 }
72 
73 int64_t
75 {
77 }
78 
81 {
82  return Range<int64_t> (start(), end());
83 }
84 
85 size_t
87 {
89 }
90 
91 bool
92 mem_node::contains (int64_t const &location) const
93 {
94  if (start() <= location && end() > location)
95  return true;
96 
97  return false;
98 }
99 
100 /* nodes can not be sparse */
101 bool
102 mem_node::canAccept (int64_t const &location) const
103 {
104  if (location == end() && space() > 0)
105  return true;
106 
107  return false;
108 }
109 
110 bool
111 mem_node::operator < (mem_node const & rhs) const
112 {
113  return start() < rhs.start();
114 }
115 
bool contains(int64_t const &location) const
Definition: mem_node.cc:92
#define assert(EX)
Definition: assert.h:17
char data[SM_PAGE_SIZE]
Definition: mem_node.h:37
void memNodeWriteComplete(void *d)
Definition: mem_node.cc:37
bool operator<(mem_node const &rhs) const
Definition: mem_node.cc:111
Definition: Range.h:18
char * p
Definition: membanger.c:43
static size_t StoreMemSize()
Definition: mem_node.cc:61
size_t space() const
Definition: mem_node.cc:86
int64_t end() const
Definition: mem_node.cc:74
bool write_pending
Definition: mem_node.h:38
void const char HLPCB void * data
Definition: stub_helper.cc:16
int64_t offset
Definition: StoreIOBuffer.h:55
static ptrdiff_t _mem_node_data_offset
Definition: mem_node.cc:17
static size_t InUseCount()
Definition: mem_node.cc:55
mem_node(int64_t)
Definition: mem_node.cc:44
#define SM_PAGE_SIZE
Definition: defines.h:102
StoreIOBuffer nodeBuffer
Definition: mem_node.h:35
Range< int64_t > dataRange() const
Definition: mem_node.cc:80
int64_t start() const
Definition: mem_node.cc:67
~mem_node()
Definition: mem_node.cc:51
#define false
Definition: GnuRegex.c:233
bool canAccept(int64_t const &location) const
Definition: mem_node.cc:102
static ptrdiff_t makeMemNodeDataOffset()
Definition: mem_node.cc:24

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors