|
32 | 32 | #include <stdlib.h> |
33 | 33 |
|
34 | 34 | #include "rtpp_types.h" |
| 35 | +#include "rtpp_refcnt.h" |
35 | 36 | #include "rtpp_genuid.h" |
| 37 | +#include "rtpp_genuid_fin.h" |
36 | 38 | #include "rtpp_mallocs.h" |
37 | 39 |
|
38 | 40 | struct rtpp_genuid_priv { |
39 | | - struct rtpp_genuid_obj pub; |
| 41 | + struct rtpp_genuid pub; |
40 | 42 | _Atomic(uint64_t) lastuid; |
41 | 43 | }; |
42 | 44 |
|
43 | | -static void rtpp_genuid_gen(struct rtpp_genuid_obj *, uint64_t *vp); |
44 | | -static void rtpp_genuid_dtor(struct rtpp_genuid_obj *); |
| 45 | +static uint64_t rtpp_genuid_gen(struct rtpp_genuid *); |
45 | 46 |
|
46 | | -struct rtpp_genuid_obj * |
| 47 | +DEFINE_SMETHODS(rtpp_genuid, |
| 48 | + .gen = &rtpp_genuid_gen, |
| 49 | +); |
| 50 | + |
| 51 | +struct rtpp_genuid * |
47 | 52 | rtpp_genuid_ctor(void) |
48 | 53 | { |
49 | 54 | struct rtpp_genuid_priv *pvt; |
50 | 55 |
|
51 | | - pvt = rtpp_zmalloc(sizeof(struct rtpp_genuid_priv)); |
| 56 | + pvt = rtpp_rzmalloc(sizeof(struct rtpp_genuid_priv), PVT_RCOFFS(pvt)); |
52 | 57 | if (pvt == NULL) { |
53 | 58 | goto e0; |
54 | 59 | } |
55 | 60 | atomic_init(&pvt->lastuid, 0); |
56 | | - pvt->pub.dtor = &rtpp_genuid_dtor; |
57 | | - pvt->pub.gen = &rtpp_genuid_gen; |
| 61 | +#if defined(RTPP_DEBUG) |
| 62 | + pvt->pub.smethods = GET_SMETHODS(&pvt->pub); |
| 63 | + RTPP_OBJ_DTOR_ATTACH(&pvt->pub, (rtpp_refcnt_dtor_t)&rtpp_genuid_fin, |
| 64 | + &(pvt->pub)); |
| 65 | +#endif |
58 | 66 | return (&pvt->pub); |
59 | 67 |
|
60 | 68 | e0: |
61 | 69 | return (NULL); |
62 | 70 | } |
63 | 71 |
|
64 | | -static void |
65 | | -rtpp_genuid_dtor(struct rtpp_genuid_obj *pub) |
66 | | -{ |
67 | | - struct rtpp_genuid_priv *pvt; |
68 | | - |
69 | | - PUB2PVT(pub, pvt); |
70 | | - |
71 | | - free(pvt); |
72 | | -} |
73 | | - |
74 | | -static void |
75 | | -rtpp_genuid_gen(struct rtpp_genuid_obj *pub, uint64_t *vp) |
| 72 | +static uint64_t |
| 73 | +rtpp_genuid_gen(struct rtpp_genuid *pub) |
76 | 74 | { |
77 | 75 | struct rtpp_genuid_priv *pvt; |
78 | 76 |
|
79 | 77 | PUB2PVT(pub, pvt); |
80 | 78 |
|
81 | | - *vp = atomic_fetch_add_explicit(&(pvt->lastuid), 1, |
| 79 | + return atomic_fetch_add_explicit(&(pvt->lastuid), 1, |
82 | 80 | memory_order_relaxed); |
83 | 81 | } |
0 commit comments