3 void refcount_ini(Refcount *refcount, void *obj, Transformer del)
8 pthread_mutex_init(&refcount->mtx, NULL);
11 void refcount_dst(Refcount *refcount)
13 pthread_mutex_destroy(&refcount->mtx);
16 void *refcount_inc(void *refcount)
18 Refcount *rc = refcount;
20 pthread_mutex_lock(&rc->mtx);
22 pthread_mutex_unlock(&rc->mtx);
26 void *refcount_grb(void *refcount)
28 return refcount_obj(refcount_inc(refcount));
31 void *refcount_drp(void *refcount)
33 Refcount *rc = refcount;
35 pthread_mutex_lock(&rc->mtx);
36 unsigned short count = --rc->cnt;
37 pthread_mutex_unlock(&rc->mtx);
40 return rc->del(rc->obj);
45 void *refcount_obj(void *refcount)
47 return ((Refcount *) refcount)->obj;