]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mem_node.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / mem_node.cc
CommitLineData
528b2c61 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
528b2c61 3 *
bbc27441
AJ
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.
528b2c61 7 */
8
bbc27441
AJ
9/* DEBUG: section 19 Store Memory Primitives */
10
582c2af2 11#include "squid.h"
ed6e9fb9 12#include "mem/Pool.h"
528b2c61 13#include "mem_node.h"
14
92047e46 15static ptrdiff_t makeMemNodeDataOffset();
12d74f96 16
92047e46 17static ptrdiff_t _mem_node_data_offset = makeMemNodeDataOffset();
12d74f96 18
19/*
20 * Calculate the offset between the start of a mem_node and
21 * its 'data' member
22 */
92047e46 23static ptrdiff_t
12d74f96 24makeMemNodeDataOffset()
25{
26 mem_node *p = 0L;
8abb2905 27 return ptrdiff_t(&p->data);
12d74f96 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);
3dd52a0b 41 n->write_pending = false;
12d74f96 42}
528b2c61 43
20ff3738 44mem_node::mem_node(int64_t offset) :
f53969cc
SM
45 nodeBuffer(0,offset,data),
46 write_pending(false)
20ff3738
AJ
47{
48 *data = 0;
49}
528b2c61 50
51mem_node::~mem_node()
2415e202 52{}
528b2c61 53
54size_t
55mem_node::InUseCount()
56{
9f9e06f3 57 return Pool().inUseCount();
528b2c61 58}
59
2415e202 60size_t
61mem_node::StoreMemSize()
62{
63 return InUseCount() * SM_PAGE_SIZE;
64}
65
47f6e231 66int64_t
528b2c61 67mem_node::start() const
68{
69 assert (nodeBuffer.offset >= 0);
70 return nodeBuffer.offset;
71}
72
47f6e231 73int64_t
528b2c61 74mem_node::end() const
75{
76 return nodeBuffer.offset + nodeBuffer.length;
77}
78
47f6e231 79Range<int64_t>
42a503bd 80mem_node::dataRange() const
81{
47f6e231 82 return Range<int64_t> (start(), end());
42a503bd 83}
84
528b2c61 85size_t
86mem_node::space() const
87{
88 return SM_PAGE_SIZE - nodeBuffer.length;
89}
90
91bool
47f6e231 92mem_node::contains (int64_t const &location) const
528b2c61 93{
94 if (start() <= location && end() > location)
62e76326 95 return true;
96
528b2c61 97 return false;
98}
99
100/* nodes can not be sparse */
101bool
47f6e231 102mem_node::canAccept (int64_t const &location) const
528b2c61 103{
104 if (location == end() && space() > 0)
62e76326 105 return true;
106
528b2c61 107 return false;
108}
4c50505b 109
110bool
111mem_node::operator < (mem_node const & rhs) const
112{
113 return start() < rhs.start();
114}
f53969cc 115