Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (18 sloc) 376 Bytes
#pragma once
#include "cthing.h"
#include "mem/mem.h"
CT_BEGIN_DECLS
typedef struct CT_Ref CT_Ref;
struct CT_Ref {
void (*free)(const CT_Ref *);
size_t count;
};
ct_inline void ct_ref_inc(const CT_Ref *ref) {
((CT_Ref *)ref)->count++;
}
ct_inline void ct_ref_dec(const CT_Ref *ref) {
if (--((CT_Ref *)ref)->count == 0) {
ref->free(ref);
}
}
CT_END_DECLS