blob: 67a55ed773bbf5b857ac331ff0f5b0ec4b62ad4c (
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
39
40
41
42
43
44
45
46
|
#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
namespace floormat {
template struct detail_borrowed_ptr::control_block<Foo>;
template class bptr<Foo>;
template bptr<Bar> static_pointer_cast(const bptr<Foo>&) noexcept;
} // namespace floormat
|