]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mem_node.cc
Removed squid-old.h
[thirdparty/squid.git] / src / mem_node.cc
1
2 /*
3 * $Id$
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 #include "protos.h"
39
40 static ptrdiff_t makeMemNodeDataOffset();
41
42 static ptrdiff_t _mem_node_data_offset = makeMemNodeDataOffset();
43
44 /*
45 * Calculate the offset between the start of a mem_node and
46 * its 'data' member
47 */
48 static ptrdiff_t
49 makeMemNodeDataOffset()
50 {
51 mem_node *p = 0L;
52 return ptrdiff_t(&p->data);
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 */
61 void
62 memNodeWriteComplete(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 }
68
69 mem_node::mem_node(int64_t offset):nodeBuffer(0,offset,data)
70 {}
71
72 mem_node::~mem_node()
73 {}
74
75 size_t
76 mem_node::InUseCount()
77 {
78 return Pool().inUseCount();
79 }
80
81 size_t
82 mem_node::StoreMemSize()
83 {
84 return InUseCount() * SM_PAGE_SIZE;
85 }
86
87 int64_t
88 mem_node::start() const
89 {
90 assert (nodeBuffer.offset >= 0);
91 return nodeBuffer.offset;
92 }
93
94 int64_t
95 mem_node::end() const
96 {
97 return nodeBuffer.offset + nodeBuffer.length;
98 }
99
100 Range<int64_t>
101 mem_node::dataRange() const
102 {
103 return Range<int64_t> (start(), end());
104 }
105
106 size_t
107 mem_node::space() const
108 {
109 return SM_PAGE_SIZE - nodeBuffer.length;
110 }
111
112 bool
113 mem_node::contains (int64_t const &location) const
114 {
115 if (start() <= location && end() > location)
116 return true;
117
118 return false;
119 }
120
121 /* nodes can not be sparse */
122 bool
123 mem_node::canAccept (int64_t const &location) const
124 {
125 if (location == end() && space() > 0)
126 return true;
127
128 return false;
129 }
130
131 bool
132 mem_node::operator < (mem_node const & rhs) const
133 {
134 return start() < rhs.start();
135 }