]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mem_node.cc
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / mem_node.cc
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 /* DEBUG: section 19 Store Memory Primitives */
10
11 #include "squid.h"
12 #include "mem_node.h"
13
14 static ptrdiff_t makeMemNodeDataOffset();
15
16 static ptrdiff_t _mem_node_data_offset = makeMemNodeDataOffset();
17
18 /*
19 * Calculate the offset between the start of a mem_node and
20 * its 'data' member
21 */
22 static ptrdiff_t
23 makeMemNodeDataOffset()
24 {
25 mem_node *p = 0L;
26 return ptrdiff_t(&p->data);
27 }
28
29 /*
30 * This is the callback when storeIOWrite() is done. We need to
31 * clear the write_pending flag for the mem_node. First we have
32 * to calculate the start of the mem_node based on the character
33 * buffer that we wrote. ick.
34 */
35 void
36 memNodeWriteComplete(void* d)
37 {
38 mem_node* n = (mem_node*)((char*)d - _mem_node_data_offset);
39 assert(n->write_pending);
40 n->write_pending = false;
41 }
42
43 mem_node::mem_node(int64_t offset) :
44 nodeBuffer(0,offset,data),
45 write_pending(false)
46 {
47 *data = 0;
48 }
49
50 mem_node::~mem_node()
51 {}
52
53 size_t
54 mem_node::InUseCount()
55 {
56 return Pool().inUseCount();
57 }
58
59 size_t
60 mem_node::StoreMemSize()
61 {
62 return InUseCount() * SM_PAGE_SIZE;
63 }
64
65 int64_t
66 mem_node::start() const
67 {
68 assert (nodeBuffer.offset >= 0);
69 return nodeBuffer.offset;
70 }
71
72 int64_t
73 mem_node::end() const
74 {
75 return nodeBuffer.offset + nodeBuffer.length;
76 }
77
78 Range<int64_t>
79 mem_node::dataRange() const
80 {
81 return Range<int64_t> (start(), end());
82 }
83
84 size_t
85 mem_node::space() const
86 {
87 return SM_PAGE_SIZE - nodeBuffer.length;
88 }
89
90 bool
91 mem_node::contains (int64_t const &location) const
92 {
93 if (start() <= location && end() > location)
94 return true;
95
96 return false;
97 }
98
99 /* nodes can not be sparse */
100 bool
101 mem_node::canAccept (int64_t const &location) const
102 {
103 if (location == end() && space() > 0)
104 return true;
105
106 return false;
107 }
108
109 bool
110 mem_node::operator < (mem_node const & rhs) const
111 {
112 return start() < rhs.start();
113 }