You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.4 KiB
58 lines
1.4 KiB
#ifndef _RC_H
|
|
#define _RC_H
|
|
|
|
|
|
#ifdef __cplusplus
|
|
#define _rc_restrict __restrict
|
|
extern "C" {
|
|
#else
|
|
#define _rc_restrict restrict
|
|
#endif
|
|
|
|
#include <stdbool.h>
|
|
|
|
#ifndef __GNUC__
|
|
#define _rc_attr(_)
|
|
#else
|
|
#define _rc_attr(v) __attribute__(v)
|
|
#endif
|
|
|
|
#define _rc_alloc_fn _rc_attr((returns_nonnull, malloc))
|
|
#define _rc_gmut_fn _rc_attr((nonnull))
|
|
#define _rc_mut_fn _rc_attr((pure, nonnull))
|
|
#define _rc_fn _rc_attr((const, nonnull))
|
|
|
|
#if __bool_true_false_are_defined
|
|
#define RC_TRUE true
|
|
#define RC_FALSE false
|
|
typedef bool rc_bool;
|
|
#else
|
|
#define RC_TRUE 1
|
|
#define RC_FALSE 0
|
|
typedef int rc_bool;
|
|
#endif
|
|
|
|
typedef struct rc* rc_t;
|
|
typedef struct rc_weak rc_weak_t;
|
|
|
|
typedef void* _rc_attr((may_alias)) rc_ptr_t;
|
|
typedef const void* _rc_attr((may_alias)) rc_const_ptr_t;
|
|
|
|
void* _rc_restrict rc_malloc(size_t sz) _rc_attr((malloc, alloc_size(1), returns_nonnull));
|
|
void rc_free(rc_ptr_t ptr) _rc_gmut_fn;
|
|
rc_ptr_t rc_clone(rc_const_ptr_t ptr) _rc_mut_fn _rc_attr((returns_nonnull));
|
|
|
|
size_t rc_refs(rc_const_ptr_t ptr)_rc_fn;
|
|
rc_bool rc_is_valid(rc_const_ptr_t ptr) _rc_fn;
|
|
|
|
rc_weak_t* _rc_restrict rc_downgrade(rc_const_ptr_t ptr) _rc_gmut_fn _rc_alloc_fn;
|
|
rc_ptr_t rc_weak_upgrade(const rc_weak_t * _rc_restrict weak);
|
|
void rc_weak_free(rc_weak_t* _rc_restrict ptr) _rc_gmut_fn;
|
|
rc_ptr_t rc_weak_upgrade(const rc_weak_t * _rc_restrict weak) _rc_mut_fn;
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _RC_H */
|