]> git.ipfire.org Git - thirdparty/squid.git/blame_incremental - src/mem_node.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mem_node.cc
... / ...
CommitLineData
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
15static ptrdiff_t makeMemNodeDataOffset();
16
17static ptrdiff_t _mem_node_data_offset = makeMemNodeDataOffset();
18
19/*
20 * Calculate the offset between the start of a mem_node and
21 * its 'data' member
22 */
23static ptrdiff_t
24makeMemNodeDataOffset()
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 */
36void
37memNodeWriteComplete(void* d)
38{
39 mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
40 assert(n->write_pending);
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
51mem_node::~mem_node()
52{}
53
54size_t
55mem_node::InUseCount()
56{
57 return Pool().inUseCount();
58}
59
60size_t
61mem_node::StoreMemSize()
62{
63 return InUseCount() * SM_PAGE_SIZE;
64}
65
66int64_t
67mem_node::start() const
68{
69 assert (nodeBuffer.offset >= 0);
70 return nodeBuffer.offset;
71}
72
73int64_t
74mem_node::end() const
75{
76 return nodeBuffer.offset + nodeBuffer.length;
77}
78
79Range<int64_t>
80mem_node::dataRange() const
81{
82 return Range<int64_t> (start(), end());
83}
84
85size_t
86mem_node::space() const
87{
88 return SM_PAGE_SIZE - nodeBuffer.length;
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