]> git.ipfire.org Git - thirdparty/squid.git/blame - src/mem_node.cc
Summary: mem_hdr testing and corrections.
[thirdparty/squid.git] / src / mem_node.cc
CommitLineData
528b2c61 1
2/*
4c50505b 3 * $Id: mem_node.cc,v 1.3 2003/06/24 12:30:59 robertc 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
39MemPool *mem_node::pool = NULL;
40unsigned long mem_node::store_mem_size;
41
42void *
43mem_node::operator new (size_t byteCount)
44{
45 /* derived classes with different sizes must implement their own new */
46 assert (byteCount == sizeof (mem_node));
62e76326 47
528b2c61 48 if (!pool)
62e76326 49 pool = memPoolCreate("mem_node", sizeof (mem_node));
50
528b2c61 51 return memPoolAlloc(pool);
52}
53
54void
55mem_node::operator delete (void *address)
56{
57 memPoolFree(pool, address);
58}
59
60mem_node::mem_node(off_t offset):nodeBuffer(0,offset,data), next (NULL)
62e76326 61{}
528b2c61 62
63mem_node::~mem_node()
64{
65 store_mem_size -= nodeBuffer.length;
66}
67
68size_t
69mem_node::InUseCount()
70{
71 if (!pool)
62e76326 72 return 0;
73
528b2c61 74 MemPoolStats stats;
62e76326 75
528b2c61 76 memPoolGetStats (&stats, pool);
62e76326 77
528b2c61 78 return stats.items_inuse;
79}
80
81size_t
82mem_node::start() const
83{
84 assert (nodeBuffer.offset >= 0);
85 return nodeBuffer.offset;
86}
87
88size_t
89mem_node::end() const
90{
91 return nodeBuffer.offset + nodeBuffer.length;
92}
93
94size_t
95mem_node::space() const
96{
97 return SM_PAGE_SIZE - nodeBuffer.length;
98}
99
100bool
101mem_node::contains (size_t const &location) const
102{
103 if (start() <= location && end() > location)
62e76326 104 return true;
105
528b2c61 106 return false;
107}
108
109/* nodes can not be sparse */
110bool
111mem_node::canAccept (size_t const &location) const
112{
113 if (location == end() && space() > 0)
62e76326 114 return true;
115
528b2c61 116 return false;
117}
4c50505b 118
119bool
120mem_node::operator < (mem_node const & rhs) const
121{
122 return start() < rhs.start();
123}