refcount Atomic Reference Counting C API (User)


refcount.h core library header


[API Types]

typedef struct refcount_s refcount_t;

typedef void (*refcount_fpdtor_t) (void*);

[API Functions]

void refcount_libinit(void);

int refcount_init(refcount_t*, int, refcount_fpdtor_t, void*);

void* refcount_state_load_depends(refcount_t volatile*);

refcount_t* refcount_add_load_strong(refcount_t* volatile*, int);

int refcount_sub_strong(refcount_t volatile*, int);

refcount_t* refcount_add_swap_weak(refcount_t* volatile*, refcount_t*, int);

void refcount_add_weak(refcount_t volatile*,int);


The refcount.h is the core library header of the refcount library; it declares the entire API, and all of its types. All API calls adhere to the C calling convention and are declared extern C when __cplusplus is defined.

The refcount.h header contains the refcount_t type which represents a reference count object. Pointers to this type are required for every API call except refcount_libinit(). The header also provides the refcount_fpdtor_t type which represents a function pointer to a destructor function. Any function that you point this to MUST follow the C calling convention and must be declared extern when every __cplusplus is defined. You will experience undefined behavior if you point this function pointer to an invalid function.


The refcount_libinit() function will fail if:

[Undefined Behavior] - You pointed refcount_fpdtor_t to a function that is not compatiable.