move refcount to header

This commit is contained in:
2026-09-28 23:59:54 +02:00
parent 4a20a5b0af
commit 91b035c2a2
3 changed files with 14 additions and 21 deletions
+14 -3
View File
@@ -8,6 +8,17 @@ struct refcount {
_Atomic(size_t) count;
};
void refcount_init(struct refcount* rc);
void refcount_inc(struct refcount* rc);
bool refcount_dec(struct refcount* rc);
static inline void refcount_init(struct refcount* rc) {
atomic_store_explicit(&rc->count, 1, memory_order_relaxed);
}
static inline void refcount_inc(struct refcount* rc) {
atomic_fetch_add_explicit(&rc->count, 1, memory_order_relaxed);
}
static inline bool refcount_dec(struct refcount* rc) {
if (atomic_fetch_sub_explicit(&rc->count, 1, memory_order_release) != 1)
return false;
atomic_thread_fence(memory_order_acquire);
return true;
}