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

 

Introduction

Documentation

Support

Miscellaneous