12#ifndef ZEPHYR_INCLUDE_SYS_REF_H_
13#define ZEPHYR_INCLUDE_SYS_REF_H_
39#define SYS_REFCOUNT_SATURATED LONG_MAX
62#define SYS_REFCOUNT_INITIALIZER { .value = ATOMIC_INIT(1) }
87 __ASSERT(old != 0,
"Increment of zero reference counter");
89 if (old == SYS_REFCOUNT_SATURATED) {
117 if (old == SYS_REFCOUNT_SATURATED) {
121 __ASSERT(old > 0,
"Decrement of zero reference counter");
165#define SYS_REF_INITIALIZER { .refcount = SYS_REFCOUNT_INITIALIZER }
231 __ASSERT_NO_MSG(release !=
NULL);
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
atomic_t atomic_val_t
Value type for atomic integer variables.
Definition atomic_types.h:38
atomic_val_t atomic_get(const atomic_t *target)
Atomic get.
atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
Atomic get-and-set.
bool atomic_cas(atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
Atomic compare-and-set.
static void sys_refcount_inc(struct sys_refcount *const rc)
Increment a reference counter.
Definition ref.h:82
static bool sys_ref_put(struct sys_ref *const ref, const sys_ref_release_t release)
Decrease reference of an object.
Definition ref.h:228
static void sys_ref_get(struct sys_ref *const ref)
Increase reference of an object.
Definition ref.h:191
static void sys_refcount_init(struct sys_refcount *const rc)
Initialize a reference counter to one.
Definition ref.h:69
static bool sys_refcount_dec(struct sys_refcount *const rc)
Decrement a reference counter.
Definition ref.h:112
static void sys_ref_init(struct sys_ref *const ref)
Initialize a reference to one.
Definition ref.h:176
void(* sys_ref_release_t)(struct sys_ref *const ref)
Release handler called once the last reference is dropped.
Definition ref.h:138
#define NULL
Definition iar_missing_defs.h:20
Reference of an object.
Definition ref.h:147
struct sys_refcount refcount
Reference counter.
Definition ref.h:149
Reference counter.
Definition ref.h:51
atomic_t value
Counter value.
Definition ref.h:53
Header file for the Atomic operations API.