9 static void * (* REF_realloc)(
void *, size_t) = realloc;
10 static void * (* REF_malloc)(size_t) = malloc;
18 #define ref_upcast(DAT) \
19 (struct refcount_ *)((char *)(DAT - offsetof(struct refcount_, data)))
21 #define ref_barrier(CODE) \
22 pthread_mutex_lock(&refc->mux); \
24 pthread_mutex_unlock(&refc->mux)
29 void * (*callocf)(
size_t,
size_t),
30 void *(*reallocf)(
void *,
size_t),
31 void (*freef)(
void *))
65 pthread_mutexattr_t attr;
70 pthread_mutexattr_init(&attr);
71 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
72 pthread_mutex_init(&refc->
mux, &attr);
83 if (--refc->
count == 0)
85 pthread_mutex_unlock(&refc->mux);
86 pthread_mutex_destroy(&refc->mux);
87 return REF_free(refc);