]>
Commit | Line | Data |
---|---|---|
528b2c61 | 1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
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. | |
26ac0430 | 24 | * |
528b2c61 | 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. | |
26ac0430 | 29 | * |
528b2c61 | 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 | ||
92047e46 | 39 | static ptrdiff_t makeMemNodeDataOffset(); |
12d74f96 | 40 | |
92047e46 | 41 | static ptrdiff_t _mem_node_data_offset = makeMemNodeDataOffset(); |
12d74f96 | 42 | |
43 | /* | |
44 | * Calculate the offset between the start of a mem_node and | |
45 | * its 'data' member | |
46 | */ | |
92047e46 | 47 | static ptrdiff_t |
12d74f96 | 48 | makeMemNodeDataOffset() |
49 | { | |
50 | mem_node *p = 0L; | |
92047e46 | 51 | return &p->data; |
12d74f96 | 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 | } | |
528b2c61 | 67 | |
47f6e231 | 68 | mem_node::mem_node(int64_t offset):nodeBuffer(0,offset,data) |
62e76326 | 69 | {} |
528b2c61 | 70 | |
71 | mem_node::~mem_node() | |
2415e202 | 72 | {} |
528b2c61 | 73 | |
74 | size_t | |
75 | mem_node::InUseCount() | |
76 | { | |
9f9e06f3 | 77 | return Pool().inUseCount(); |
528b2c61 | 78 | } |
79 | ||
2415e202 | 80 | size_t |
81 | mem_node::StoreMemSize() | |
82 | { | |
83 | return InUseCount() * SM_PAGE_SIZE; | |
84 | } | |
85 | ||
47f6e231 | 86 | int64_t |
528b2c61 | 87 | mem_node::start() const |
88 | { | |
89 | assert (nodeBuffer.offset >= 0); | |
90 | return nodeBuffer.offset; | |
91 | } | |
92 | ||
47f6e231 | 93 | int64_t |
528b2c61 | 94 | mem_node::end() const |
95 | { | |
96 | return nodeBuffer.offset + nodeBuffer.length; | |
97 | } | |
98 | ||
47f6e231 | 99 | Range<int64_t> |
42a503bd | 100 | mem_node::dataRange() const |
101 | { | |
47f6e231 | 102 | return Range<int64_t> (start(), end()); |
42a503bd | 103 | } |
104 | ||
528b2c61 | 105 | size_t |
106 | mem_node::space() const | |
107 | { | |
108 | return SM_PAGE_SIZE - nodeBuffer.length; | |
109 | } | |
110 | ||
111 | bool | |
47f6e231 | 112 | mem_node::contains (int64_t const &location) const |
528b2c61 | 113 | { |
114 | if (start() <= location && end() > location) | |
62e76326 | 115 | return true; |
116 | ||
528b2c61 | 117 | return false; |
118 | } | |
119 | ||
120 | /* nodes can not be sparse */ | |
121 | bool | |
47f6e231 | 122 | mem_node::canAccept (int64_t const &location) const |
528b2c61 | 123 | { |
124 | if (location == end() && space() > 0) | |
62e76326 | 125 | return true; |
126 | ||
528b2c61 | 127 | return false; |
128 | } | |
4c50505b | 129 | |
130 | bool | |
131 | mem_node::operator < (mem_node const & rhs) const | |
132 | { | |
133 | return start() < rhs.start(); | |
134 | } |