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
15static ptrdiff_t makeMemNodeDataOffset();
16
18
19/*
20 * Calculate the offset between the start of a mem_node and
21 * its 'data' member
22 */
23static ptrdiff_t
25{
26 mem_node *p = nullptr;
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 */
36void
38{
39 mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
41 n->write_pending = false;
42}
43
44mem_node::mem_node(int64_t offset) :
45 nodeBuffer(0,offset,data),
46 write_pending(false)
47{
48 *data = 0;
49}
50
52{}
53
54size_t
56{
57 return Pool().inUseCount();
58}
59
60size_t
62{
63 return InUseCount() * SM_PAGE_SIZE;
64}
65
66int64_t
68{
70 return nodeBuffer.offset;
71}
72
73int64_t
75{
77}
78
81{
82 return Range<int64_t> (start(), end());
83}
84
85size_t
87{
89}
90
91bool
92mem_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 */
101bool
102mem_node::canAccept (int64_t const &location) const
103{
104 if (location == end() && space() > 0)
105 return true;
106
107 return false;
108}
109
110bool
111mem_node::operator < (mem_node const & rhs) const
112{
113 return start() < rhs.start();
114}
115
#define assert(EX)
Definition: assert.h:17
Definition: Range.h:19
int64_t offset
Definition: StoreIOBuffer.h:58
StoreIOBuffer nodeBuffer
Definition: mem_node.h:35
Range< int64_t > dataRange() const
Definition: mem_node.cc:80
size_t space() const
Definition: mem_node.cc:86
bool operator<(mem_node const &rhs) const
Definition: mem_node.cc:111
char data[SM_PAGE_SIZE]
Definition: mem_node.h:37
static size_t StoreMemSize()
Definition: mem_node.cc:61
~mem_node()
Definition: mem_node.cc:51
bool canAccept(int64_t const &location) const
Definition: mem_node.cc:102
bool contains(int64_t const &location) const
Definition: mem_node.cc:92
static size_t InUseCount()
Definition: mem_node.cc:55
int64_t end() const
Definition: mem_node.cc:74
mem_node(int64_t)
Definition: mem_node.cc:44
int64_t start() const
Definition: mem_node.cc:67
bool write_pending
Definition: mem_node.h:38
#define SM_PAGE_SIZE
Definition: defines.h:65
static ptrdiff_t _mem_node_data_offset
Definition: mem_node.cc:17
static ptrdiff_t makeMemNodeDataOffset()
Definition: mem_node.cc:24
void memNodeWriteComplete(void *d)
Definition: mem_node.cc:37

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors