12#ifndef ROC_CORE_REF_COUNTED_H_
13#define ROC_CORE_REF_COUNTED_H_
37template <
class T,
class AllocationPolicy>
39 protected AllocationPolicy {
49 : AllocationPolicy(policy)
55 roc_panic(
"ref counter: attempt to destroy object that is still in use: "
68 const int previous_counter = counter_++;
70 if (previous_counter < 0) {
71 roc_panic(
"ref counter: attempt to call acquire on destroyed object");
79 const int previous_counter = counter_--;
81 if (previous_counter < 0) {
82 roc_panic(
"ref counter: attempt to call release on destroyed object");
85 if (previous_counter == 0) {
86 roc_panic(
"ref counter: attempt to call release without acquire");
89 if (previous_counter == 1) {
91 static_cast<T&
>(
const_cast<RefCounted&
>(*
this)));
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
bool compare_exchange(T exp, T des)
Atomic compare-and-swap.
Base class for non-copyable objects.
Base class for reference counted object.
void incref() const
Increment reference counter.
RefCounted(const AllocationPolicy &policy)
Initialization with arbitrary allocation policy.
long getref() const
Get reference counter.
RefCounted()
Initialization with default allocation policy.
void decref() const
Decrement reference counter.
#define roc_panic(...)
Print error message and terminate program gracefully.