diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-16 10:52:09 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-07-16 11:34:06 +0200 |
commit | eba565a6359957a7ba5c3af645af36eefd58fbf3 (patch) | |
tree | b0af5bb6d07dac275b6b91a91ddf74c074a15f91 /compat/borrowed-ptr.cpp | |
parent | e8ba17588d7ba8d047b32bd3aca1aee501512342 (diff) |
w
Diffstat (limited to 'compat/borrowed-ptr.cpp')
-rw-r--r-- | compat/borrowed-ptr.cpp | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/compat/borrowed-ptr.cpp b/compat/borrowed-ptr.cpp index f6f098fa..3048e48a 100644 --- a/compat/borrowed-ptr.cpp +++ b/compat/borrowed-ptr.cpp @@ -4,15 +4,37 @@ namespace floormat::detail_bptr { void control_block::decrement(control_block*& blk) noexcept { - auto c = --blk->_count; + auto c2 = --blk->_hard_count; + fm_bptr_assert(c2 != (uint32_t)-1); + if (c2 == 0) + { + delete blk->_ptr; + blk->_ptr = nullptr; + } + + auto c = --blk->_soft_count; fm_bptr_assert(c != (uint32_t)-1); if (c == 0) { - delete blk->_ptr; + fm_bptr_assert(!blk->_ptr); + delete blk; + } + blk = nullptr; +} + +void control_block::weak_decrement(control_block*& blk) noexcept +{ + if (!blk) + return; + fm_bptr_assert(blk->_hard_count < blk->_soft_count); + auto c = --blk->_soft_count; + //fm_bptr_assert(c != (uint32_t)-1); + if (c == 0) + { + fm_bptr_assert(!blk->_ptr); delete blk; } blk = nullptr; - //blk = (control_block*)-1; } } // namespace floormat::detail_bptr |