Reference count
include/types/refcount.h View source View on GitHubFunctions
Section titled “Functions”refcount_init
Section titled “refcount_init”void refcount_init(refcount_t *rc, uint32_t val); refcount_inc
Section titled “refcount_inc”bool refcount_inc(refcount_t *rc); refcount_inc_not_zero
Section titled “refcount_inc_not_zero”bool refcount_inc_not_zero(refcount_t *rc); refcount_read
Section titled “refcount_read”uint32_t refcount_read(refcount_t *rc); refcount_dec_and_test
Section titled “refcount_dec_and_test”bool refcount_dec_and_test(refcount_t *rc); Macros
Section titled “Macros”REFCOUNT_GENERATE_GET_FOR_STRUCT_WITH_FAILURE_COND
Section titled “REFCOUNT_GENERATE_GET_FOR_STRUCT_WITH_FAILURE_COND”#define REFCOUNT_GENERATE_GET_FOR_STRUCT_WITH_FAILURE_COND( \
__struct, __refcount_member, __failure_member, __failure_state) \
static inline bool __struct##_get(struct __struct *obj) { \
uint32_t old; \
while (true) { \
old = atomic_load_explicit(&obj->__refcount_member, \
memory_order_acquire); \
\
/* panic if refcount is zero (possible UAF) */ REFCOUNT_ASSERT_ZERO
Section titled “REFCOUNT_ASSERT_ZERO”#define REFCOUNT_ASSERT_ZERO(rc) (kassert(atomic_load(&rc) == 0))