]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/mem_node.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 19 Store Memory Primitives */
16 #include <type_traits>
18 static ptrdiff_t makeMemNodeDataOffset();
20 static ptrdiff_t _mem_node_data_offset
= makeMemNodeDataOffset();
23 * Calculate the offset between the start of a mem_node and
27 makeMemNodeDataOffset()
29 static_assert(std::is_standard_layout
<mem_node
>::value
, "offsetof(mem_node) is unconditionally supported");
30 return ptrdiff_t(offsetof(mem_node
, data
));
34 * This is the callback when storeIOWrite() is done. We need to
35 * clear the write_pending flag for the mem_node. First we have
36 * to calculate the start of the mem_node based on the character
37 * buffer that we wrote. ick.
40 memNodeWriteComplete(void* d
)
42 mem_node
* n
= (mem_node
*)((char*)d
- _mem_node_data_offset
);
43 assert(n
->write_pending
);
44 n
->write_pending
= false;
47 mem_node::mem_node(int64_t offset
) :
48 nodeBuffer(0,offset
,data
),
58 mem_node::InUseCount()
60 return Pool().inUseCount();
64 mem_node::StoreMemSize()
66 return InUseCount() * SM_PAGE_SIZE
;
70 mem_node::start() const
72 assert (nodeBuffer
.offset
>= 0);
73 return nodeBuffer
.offset
;
79 return nodeBuffer
.offset
+ nodeBuffer
.length
;
83 mem_node::dataRange() const
85 return Range
<int64_t> (start(), end());
89 mem_node::space() const
91 return SM_PAGE_SIZE
- nodeBuffer
.length
;
95 mem_node::contains (int64_t const &location
) const
97 if (start() <= location
&& end() > location
)
103 /* nodes can not be sparse */
105 mem_node::canAccept (int64_t const &location
) const
107 if (location
== end() && space() > 0)
114 mem_node::operator < (mem_node
const & rhs
) const
116 return start() < rhs
.start();