74#define CSTL_GUARDED_PTR_INITIALIZER(NAME) \
84#define DECLARE_CSTL_GUARDED_PTR(NAME) \
85 struct cstl_guarded_ptr NAME = \
86 CSTL_GUARDED_PTR_INITIALIZER(NAME)
141 if (gp->self != gp) {
213#define CSTL_UNIQUE_PTR_INITIALIZER(NAME) \
215 .gp = CSTL_GUARDED_PTR_INITIALIZER(NAME.gp), \
226#define DECLARE_CSTL_UNIQUE_PTR(NAME) \
227 cstl_unique_ptr_t NAME = \
228 CSTL_UNIQUE_PTR_INITIALIZER(NAME)
320 *priv = up->clr.priv;
335 uint8_t t[
sizeof(up1->clr)];
337 cstl_swap(&up1->clr, &up2->clr, t,
sizeof(t));
380#define CSTL_SHARED_PTR_INITIALIZER(NAME) \
382 .data = CSTL_GUARDED_PTR_INITIALIZER(NAME.data), \
389#define DECLARE_CSTL_SHARED_PTR(NAME) \
390 cstl_shared_ptr_t NAME = CSTL_SHARED_PTR_INITIALIZER(NAME)
512#define CSTL_WEAK_PTR_INITIALIZER(NAME) \
513 CSTL_SHARED_PTR_INITIALIZER(NAME)
519#define DECLARE_CSTL_WEAK_PTR(NAME) \
520 cstl_weak_ptr_t NAME = CSTL_WEAK_PTR_INITIALIZER(NAME)
static void cstl_swap(void *const x, void *const y, void *const t, const size_t sz)
Swap values at two memory locations via use of a third.
void cstl_xtor_func_t(void *obj, void *priv)
Type for functions called to construct, clear, or destroy an object.
static void cstl_guarded_ptr_set(struct cstl_guarded_ptr *const gp, void *const ptr)
Initialize a guarded pointer object to a specific pointer value.
static void cstl_guarded_ptr_copy(struct cstl_guarded_ptr *const dst, const struct cstl_guarded_ptr *const src)
Copy the cstl_guarded_ptr object to a new location.
static void cstl_guarded_ptr_init(struct cstl_guarded_ptr *const gp)
Initialize a guarded pointer object to NULL.
static const void * cstl_guarded_ptr_get_const(const struct cstl_guarded_ptr *const gp)
Retrieve the stored pointer value.
static void cstl_guarded_ptr_swap(struct cstl_guarded_ptr *const a, struct cstl_guarded_ptr *const b)
Swap the pointers pointed to by the objects.
static void * cstl_guarded_ptr_get(struct cstl_guarded_ptr *const gp)
Retrieve the stored pointer value.
static void cstl_shared_ptr_swap(cstl_shared_ptr_t *const sp1, cstl_shared_ptr_t *const sp2)
Swap the memory managed by the two objects.
void cstl_shared_ptr_reset(cstl_shared_ptr_t *sp)
Stop managing the underlying memory via this object.
bool cstl_shared_ptr_unique(const cstl_shared_ptr_t *sp)
Determine if a shared pointer uniquely owns the underlying memory.
static void * cstl_shared_ptr_get(cstl_shared_ptr_t *const sp)
Get a pointer to the memory managed by the object.
void cstl_shared_ptr_share(const cstl_shared_ptr_t *ex, cstl_shared_ptr_t *n)
Create a new shared pointer object to manage the underlying memory.
void cstl_shared_ptr_alloc(cstl_shared_ptr_t *sp, size_t sz, cstl_xtor_func_t *clr)
Dynamically allocated memory to be shared via the object.
const void * cstl_shared_ptr_get_const(const cstl_shared_ptr_t *)
Get a pointer to the memory managed by the object.
static void cstl_shared_ptr_init(cstl_shared_ptr_t *const sp)
Initialize a shared pointer object.
static void cstl_unique_ptr_swap(cstl_unique_ptr_t *const up1, cstl_unique_ptr_t *const up2)
Swap the objects pointed to by the parameters.
static void cstl_unique_ptr_init(cstl_unique_ptr_t *const up)
Initialize a unique pointer.
static void * cstl_unique_ptr_get(cstl_unique_ptr_t *const up)
Get the pointer managed by the unique pointer object.
void cstl_unique_ptr_reset(cstl_unique_ptr_t *up)
Free the memory managed by a unique pointer.
void cstl_unique_ptr_alloc(cstl_unique_ptr_t *up, size_t len, cstl_xtor_func_t *clr, void *priv)
Dynamically allocate memory to be managed by the unique pointer.
static void * cstl_unique_ptr_release(cstl_unique_ptr_t *const up, cstl_xtor_func_t **const clr, void **priv)
Stop a unique pointer object from managing a pointer.
static const void * cstl_unique_ptr_get_const(const cstl_unique_ptr_t *const up)
Get the pointer managed by the unique pointer object.
void cstl_weak_ptr_reset(cstl_weak_ptr_t *)
Drop the reference to the underlying managed memory.
static void cstl_weak_ptr_init(cstl_weak_ptr_t *const wp)
Initialize a weak pointer object.
static void cstl_weak_ptr_swap(cstl_weak_ptr_t *const wp1, cstl_weak_ptr_t *const wp2)
Swap the memory managed by the two weak pointer objects.
cstl_shared_ptr_t cstl_weak_ptr_t
The weak pointer object.
void cstl_weak_ptr_from(cstl_weak_ptr_t *wp, const cstl_shared_ptr_t *sp)
Create a weak pointer from a shared pointer.
void cstl_weak_ptr_lock(const cstl_weak_ptr_t *wp, cstl_shared_ptr_t *sp)
Convert a weak pointer to a shared pointer.
Structure to hold a pointer and guard against its direct copying.
The shared pointer object.
A pointer that has a single "owner".