blob: 2eac9ad776317e7ee1d7a56879af4835035f249d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include "borrowed-ptr.inl"
#include "compat/assert.hpp"
namespace floormat::detail_borrowed_ptr {
control_block_::control_block_(void* ptr) noexcept: _ptr{ptr}, _count{1}
{
fm_debug_assert(ptr);
}
void control_block_::incr() noexcept
{
auto val = ++_count;
(void)val;
fm_debug_assert(val > 1);
}
void control_block_::decr() noexcept
{
auto val = --_count;
fm_debug_assert(val != (uint32_t)-1);
if (val == 0)
{
free();
_ptr = nullptr;
}
}
control_block_::~control_block_() noexcept { decr(); }
uint32_t control_block_::count() const noexcept { return _count; }
} // namespace floormat::detail_borrowed_ptr
namespace {
struct Foo {};
struct Bar : Foo {};
struct Baz {};
} // namespace
|