]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mem_node.cc
Renamed squid.h to squid-old.h and config.h to squid.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-old.h"
37 #include "mem_node.h"
38
39 static ptrdiff_t makeMemNodeDataOffset();
40
41 static ptrdiff_t _mem_node_data_offset = makeMemNodeDataOffset();
42
43 /*
44 * Calculate the offset between the start of a mem_node and
45 * its 'data' member
46 */
47 static ptrdiff_t
48 makeMemNodeDataOffset()
49 {
50 mem_node *p = 0L;
51 return ptrdiff_t(&p->data);
52 }
53
54 /*
55 * This is the callback when storeIOWrite() is done. We need to
56 * clear the write_pending flag for the mem_node. First we have
57 * to calculate the start of the mem_node based on the character
58 * buffer that we wrote. ick.
59 */
60 void
61 memNodeWriteComplete(void* d)
62 {
63 mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
64 assert(n->write_pending);
65 n->write_pending = 0;
66 }
67
68 mem_node::mem_node(int64_t offset):nodeBuffer(0,offset,data)
69 {}
70
71 mem_node::~mem_node()
72 {}
73
74 size_t
75 mem_node::InUseCount()
76 {
77 return Pool().inUseCount();
78 }
79
80 size_t
81 mem_node::StoreMemSize()
82 {
83 return InUseCount() * SM_PAGE_SIZE;
84 }
85
86 int64_t
87 mem_node::start() const
88 {
89 assert (nodeBuffer.offset >= 0);
90 return nodeBuffer.offset;
91 }
92
93 int64_t
94 mem_node::end() const
95 {
96 return nodeBuffer.offset + nodeBuffer.length;
97 }
98
99 Range<int64_t>
100 mem_node::dataRange() const
101 {
102 return Range<int64_t> (start(), end());
103 }
104
105 size_t
106 mem_node::space() const
107 {
108 return SM_PAGE_SIZE - nodeBuffer.length;
109 }
110
111 bool
112 mem_node::contains (int64_t const &location) const
113 {
114 if (start() <= location && end() > location)
115 return true;
116
117 return false;
118 }
119
120 /* nodes can not be sparse */
121 bool
122 mem_node::canAccept (int64_t const &location) const
123 {
124 if (location == end() && space() > 0)
125 return true;
126
127 return false;
128 }
129
130 bool
131 mem_node::operator < (mem_node const & rhs) const
132 {
133 return start() < rhs.start();
134 }