12#ifndef ROC_CORE_USAGE_COUNTER_H_
13#define ROC_CORE_USAGE_COUNTER_H_
36 roc_panic(
"usage counter: attempt to destroy object that is still in use: "
44 const int current_counter = counter_;
46 if (current_counter < 0) {
47 roc_panic(
"usage counter: attempt to access destroyed object");
50 return current_counter > 0;
55 const int previous_counter = counter_++;
57 if (previous_counter < 0) {
58 roc_panic(
"usage counter: attempt to call acquire on destroyed object");
64 const int previous_counter = counter_--;
66 if (previous_counter < 0) {
67 roc_panic(
"usage counter: attempt to call release on destroyed object");
70 if (previous_counter == 0) {
71 roc_panic(
"usage counter: attempt to call release without acquire");
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 object with usage counter.
bool is_used() const
Check whether usage counter is non-zero.
void acquire_usage() const
Increment usage counter.
void release_usage() const
Decrement usage counter.
#define roc_panic(...)
Print error message and terminate program gracefully.