summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@yahooinc.com>2023-03-07 10:44:32 +0000
committerHåvard Pettersen <havardpe@yahooinc.com>2023-03-07 10:44:32 +0000
commit1c1f8fa74527e8859154ea61d52e1871198c8caf (patch)
treebc7860a6b3c3bd4c61dd15ec03eed011b51949ed
parent028316d562f645540fb27c9be5b8c8b9249d9d11 (diff)
always check magic tag with assert
-rw-r--r--vespalib/src/vespa/vespalib/util/ref_counted.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/ref_counted.cpp b/vespalib/src/vespa/vespalib/util/ref_counted.cpp
index 43a4647e9ec..47bb59bb287 100644
--- a/vespalib/src/vespa/vespalib/util/ref_counted.cpp
+++ b/vespalib/src/vespa/vespalib/util/ref_counted.cpp
@@ -12,6 +12,7 @@ enable_ref_counted::internal_addref(uint32_t cnt) const noexcept
// the thread obtaining the new reference already has a reference
auto prev = _refs.fetch_add(cnt, std::memory_order_relaxed);
assert(prev > 0);
+ assert(_guard == MAGIC);
}
void
@@ -21,6 +22,7 @@ enable_ref_counted::internal_subref(uint32_t cnt, [[maybe_unused]] uint32_t rese
// our changes to the object must be visible to the deleter
auto prev = _refs.fetch_sub(cnt, std::memory_order_release);
assert(prev >= (reserve + cnt));
+ assert(_guard == MAGIC);
if (prev == cnt) {
// acquire because:
// we need to see all object changes before deleting it
@@ -33,6 +35,7 @@ uint32_t
enable_ref_counted::count_refs() const noexcept {
auto result = _refs.load(std::memory_order_relaxed);
assert(result > 0);
+ assert(_guard == MAGIC);
return result;
}