From 91b035c2a22fc219fb26c8484d1023775364f44a Mon Sep 17 00:00:00 2001 From: Marvin Friedrich Date: Mon, 28 Sep 2026 23:59:54 +0200 Subject: [PATCH] move refcount to header --- core/meson.build | 1 - core/refcount.c | 17 ----------------- include/zinnia/refcount.h | 17 ++++++++++++++--- 3 files changed, 14 insertions(+), 21 deletions(-) delete mode 100644 core/refcount.c diff --git a/core/meson.build b/core/meson.build index 6b7f3ef..fade04c 100644 --- a/core/meson.build +++ b/core/meson.build @@ -6,7 +6,6 @@ kernel_sources += files( 'panic.c', 'percpu.c', 'print.c', - 'refcount.c', 'spin.c', 'wait.c', ) diff --git a/core/refcount.c b/core/refcount.c deleted file mode 100644 index 4655528..0000000 --- a/core/refcount.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -void refcount_init(struct refcount* rc) { - atomic_store_explicit(&rc->count, 1, memory_order_relaxed); -} - -void refcount_inc(struct refcount* rc) { - atomic_fetch_add_explicit(&rc->count, 1, memory_order_relaxed); -} - -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; -} diff --git a/include/zinnia/refcount.h b/include/zinnia/refcount.h index 9e4a835..8bd6d23 100644 --- a/include/zinnia/refcount.h +++ b/include/zinnia/refcount.h @@ -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; +}