]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mem_node.cc
Bug #2016 fix: Prevent BodyPipe async calls from getting seemingly
[thirdparty/squid.git] / src / mem_node.cc
CommitLineData
528b2c61 1
2/*
9f9e06f3 3 * $Id: mem_node.cc,v 1.9 2006/09/20 00:59:27 adrian Exp $
528b2c61 4 *
5 * DEBUG: section 19 Store Memory Primitives
6 * AUTHOR: Robert Collins
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36#include "squid.h"
37#include "mem_node.h"
38
12d74f96 39static int makeMemNodeDataOffset();
40
528b2c61 41unsigned long mem_node::store_mem_size;
12d74f96 42static int _mem_node_data_offset = makeMemNodeDataOffset();
43
44/*
45 * Calculate the offset between the start of a mem_node and
46 * its 'data' member
47 */
48static int
49makeMemNodeDataOffset()
50{
51 mem_node *p = 0L;
672a3130 52 return int(ptrdiff_t(&p->data));
12d74f96 53}
54
55/*
56 * This is the callback when storeIOWrite() is done. We need to
57 * clear the write_pending flag for the mem_node. First we have
58 * to calculate the start of the mem_node based on the character
59 * buffer that we wrote. ick.
60 */
61void
62memNodeWriteComplete(void* d)
63{
64 mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
65 assert(n->write_pending);
66 n->write_pending = 0;
67}
528b2c61 68
42a503bd 69mem_node::mem_node(off_t offset):nodeBuffer(0,offset,data)
62e76326 70{}
528b2c61 71
72mem_node::~mem_node()
73{
74 store_mem_size -= nodeBuffer.length;
75}
76
77size_t
78mem_node::InUseCount()
79{
9f9e06f3 80 return Pool().inUseCount();
528b2c61 81}
82
83size_t
84mem_node::start() const
85{
86 assert (nodeBuffer.offset >= 0);
87 return nodeBuffer.offset;
88}
89
90size_t
91mem_node::end() const
92{
93 return nodeBuffer.offset + nodeBuffer.length;
94}
95
42a503bd 96Range<size_t>
97mem_node::dataRange() const
98{
99 return Range<size_t> (start(), end());
100}
101
528b2c61 102size_t
103mem_node::space() const
104{
105 return SM_PAGE_SIZE - nodeBuffer.length;
106}
107
108bool
109mem_node::contains (size_t const &location) const
110{
111 if (start() <= location && end() > location)
62e76326 112 return true;
113
528b2c61 114 return false;
115}
116
117/* nodes can not be sparse */
118bool
119mem_node::canAccept (size_t const &location) const
120{
121 if (location == end() && space() > 0)
62e76326 122 return true;
123
528b2c61 124 return false;
125}
4c50505b 126
127bool
128mem_node::operator < (mem_node const & rhs) const
129{
130 return start() < rhs.start();
131}