Toast Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
control_box.hpp
Go to the documentation of this file.
1
8
9
#pragma once
10
11
#include <atomic>
12
#include <compare>
13
#include <cstdint>
14
#include <functional>
15
#include <
toast/export.hpp
>
16
17
namespace
toast {
18
class
Node
;
19
20
namespace
_detail
{
21
struct
WorldTestAccess
;
22
33
struct
TOAST_API
ControlBox
{
34
std::atomic<unsigned int>
ref_count
;
35
Node
*
node
=
nullptr
;
36
38
ControlBox
(
Node
* n);
39
40
ControlBox
(
const
ControlBox
&) =
delete
;
41
ControlBox
(
ControlBox
&&) =
delete
;
42
auto
operator=(
const
ControlBox
&) ->
ControlBox
& =
delete
;
43
auto
operator=(
ControlBox
&&) ->
ControlBox
& =
delete
;
44
46
explicit
operator
bool() const noexcept;
47
49
auto operator<=>(const
ControlBox
& other) const noexcept -> std::strong_ordering;
50
auto operator==(const
ControlBox
& other) const noexcept ->
bool
;
51
57
[[nodiscard]]
58
auto
rid
() const noexcept -> std::uintptr_t;
60
void
increment
();
62
void
decrement
();
63
65
static auto
get
(const
Node
*
node
) ->
ControlBox
*;
67
static auto
get
(const
Node
&
node
) ->
ControlBox
*;
68
};
69
70
}
71
}
72
73
template<>
74
struct std::hash<toast::_detail::ControlBox> {
75
auto
operator()(
const
toast::_detail::ControlBox
& a)
const
noexcept
-> std::size_t {
76
return
std::hash<std::uintptr_t> {}(a.
rid
());
77
}
78
};
toast::Node
Definition
node.hpp:81
export.hpp
toast::_detail
Member-robber pattern used by the generated reflection code.
Definition
defer.hpp:16
toast::_detail::ControlBox
Reference-count control block embedded inside the Node allocation.
Definition
control_box.hpp:33
toast::_detail::ControlBox::get
static auto get(const Node *node) -> ControlBox *
Recovers the ControlBox from a raw node pointer; the ControlBox sits immediately before the Node in m...
Definition
control_box.cpp:37
toast::_detail::ControlBox::increment
void increment()
relaxed acquire; acquiring a Box is always preceded by an acquire elsewhere
Definition
control_box.cpp:29
toast::_detail::ControlBox::node
Node * node
null once the node is destroyed
Definition
control_box.hpp:35
toast::_detail::ControlBox::decrement
void decrement()
acq_rel release; ensures the last releaser sees all prior writes before decrementing
Definition
control_box.cpp:33
toast::_detail::ControlBox::rid
auto rid() const noexcept -> std::uintptr_t
Stable numeric identity for this ControlBox.
Definition
control_box.cpp:25
toast::_detail::ControlBox::ref_count
std::atomic< unsigned int > ref_count
starts at 1 (the node's self-reference); node is freed when it hits 0
Definition
control_box.hpp:34
toast::_detail::ControlBox::ControlBox
ControlBox(Node *n)
Initializes ref_count to 1 and stores the node pointer; called by nodeAllocation().
Definition
control_box.cpp:7
toast::_detail::WorldTestAccess
Definition
world_test_access.hpp:14
engine
src
toast
world
control_box.hpp
Generated by
1.17.0