summaryrefslogtreecommitdiffhomepage
path: root/compat/borrowed-ptr.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-05-04 12:56:21 +0200
committerStanislaw Halik <sthalik@misaki.pl>2024-05-05 03:31:18 +0200
commit4c276b1b1b946e4b08eb7b92a24d30bdc55106fd (patch)
tree981ef0a821714edcb7e11543fb952b41be2d1ec6 /compat/borrowed-ptr.cpp
parent88f6fe2b4c51fd318a1ce8994d7affb35696d418 (diff)
wip bptr
Diffstat (limited to 'compat/borrowed-ptr.cpp')
-rw-r--r--compat/borrowed-ptr.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/compat/borrowed-ptr.cpp b/compat/borrowed-ptr.cpp
new file mode 100644
index 00000000..8c05b751
--- /dev/null
+++ b/compat/borrowed-ptr.cpp
@@ -0,0 +1,41 @@
+#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 floormat {
+
+namespace { struct Foo {}; }
+
+template struct detail_borrowed_ptr::control_block<Foo>;
+template class bptr<Foo>;
+
+} // namespace floormat