|
PatchworkOS
19e446b
A non-POSIX operating system.
|
#include <kernel/sync/lock.h>#include <sys/defs.h>#include <sys/list.h>#include <assert.h>#include <stdatomic.h>#include <stdint.h>Go to the source code of this file.
Data Structures | |
| struct | weak_ptr_t |
| Weak pointer structure. More... | |
| struct | ref_t |
| Reference counting structure. More... | |
Macros | |
| #define | REF_MAGIC 0x26CB6E4C |
Magic value used in debug builds to check for corruption or invalid use of the ref_t structure. | |
| #define | REF_COUNT(ptr) ((ptr) == NULL ? 0 : atomic_load_explicit(&((ref_t*)(ptr))->count, memory_order_relaxed)) |
| Get current reference count. | |
| #define | REF(ptr) |
| Increment reference count. | |
| #define | REF_TRY(ptr) |
| Increment reference count, but only if the current count is not zero. | |
| #define | UNREF(ptr) |
| Decrement reference count. | |
| #define | UNREF_DEFER(ptr) __attribute__((cleanup(ref_defer_cleanup))) void* CONCAT(p, __COUNTER__) = (ptr) |
| RAII-style cleanup for scoped references. | |
Typedefs | |
| typedef struct ref | ref_t |
Functions | |
| static void | ref_init (ref_t *ref, void *callback) |
| Initialize a reference counter. | |
| static void * | ref_inc (void *ptr) |
| Increment reference count. | |
| static void * | ref_inc_try (void *ptr) |
| Increment reference count, but only if the current count is not zero. | |
| static void | ref_dec (void *ptr) |
| Decrement reference count. | |
| static void | ref_defer_cleanup (void **ptr) |
| static void | weak_ptr_set (weak_ptr_t *wp, ref_t *ref, void(*callback)(void *), void *arg) |
| Set a weak pointer. | |
| static void | weak_ptr_clear (weak_ptr_t *wp) |
| Clear a weak pointer. | |
| static void * | weak_ptr_get (weak_ptr_t *wp) |
| Upgrade a weak pointer to a strong pointer. | |