]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | |
2 | /* | |
47f6e231 | 3 | * $Id: mem_node.cc,v 1.10 2007/08/13 17:20:51 hno 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 | 39 | static int makeMemNodeDataOffset(); |
40 | ||
528b2c61 | 41 | unsigned long mem_node::store_mem_size; |
12d74f96 | 42 | static 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 | */ | |
48 | static int | |
49 | makeMemNodeDataOffset() | |
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 | */ | |
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 | } | |
528b2c61 | 68 | |
47f6e231 | 69 | mem_node::mem_node(int64_t offset):nodeBuffer(0,offset,data) |
62e76326 | 70 | {} |
528b2c61 | 71 | |
72 | mem_node::~mem_node() | |
73 | { | |
74 | store_mem_size -= nodeBuffer.length; | |
75 | } | |
76 | ||
77 | size_t | |
78 | mem_node::InUseCount() | |
79 | { | |
9f9e06f3 | 80 | return Pool().inUseCount(); |
528b2c61 | 81 | } |
82 | ||
47f6e231 | 83 | int64_t |
528b2c61 | 84 | mem_node::start() const |
85 | { | |
86 | assert (nodeBuffer.offset >= 0); | |
87 | return nodeBuffer.offset; | |
88 | } | |
89 | ||
47f6e231 | 90 | int64_t |
528b2c61 | 91 | mem_node::end() const |
92 | { | |
93 | return nodeBuffer.offset + nodeBuffer.length; | |
94 | } | |
95 | ||
47f6e231 | 96 | Range<int64_t> |
42a503bd | 97 | mem_node::dataRange() const |
98 | { | |
47f6e231 | 99 | return Range<int64_t> (start(), end()); |
42a503bd | 100 | } |
101 | ||
528b2c61 | 102 | size_t |
103 | mem_node::space() const | |
104 | { | |
105 | return SM_PAGE_SIZE - nodeBuffer.length; | |
106 | } | |
107 | ||
108 | bool | |
47f6e231 | 109 | mem_node::contains (int64_t const &location) const |
528b2c61 | 110 | { |
111 | if (start() <= location && end() > location) | |
62e76326 | 112 | return true; |
113 | ||
528b2c61 | 114 | return false; |
115 | } | |
116 | ||
117 | /* nodes can not be sparse */ | |
118 | bool | |
47f6e231 | 119 | mem_node::canAccept (int64_t const &location) const |
528b2c61 | 120 | { |
121 | if (location == end() && space() > 0) | |
62e76326 | 122 | return true; |
123 | ||
528b2c61 | 124 | return false; |
125 | } | |
4c50505b | 126 | |
127 | bool | |
128 | mem_node::operator < (mem_node const & rhs) const | |
129 | { | |
130 | return start() < rhs.start(); | |
131 | } |