| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "rist_ref.h" |
| 9 |
#include <stdlib.h> |
| 10 |
#include <stdbool.h> |
| 11 |
|
| 12 |
struct rist_ref *rist_ref_create(void *data) |
| 13 |
{ |
| 14 |
struct rist_ref *ref = malloc(sizeof(*ref)); |
| 15 |
if (!ref) |
| 16 |
return NULL; |
| 17 |
ref->ptr = data; |
| 18 |
atomic_init(&ref->refcnt, 1); |
| 19 |
return ref; |
| 20 |
} |
| 21 |
|
| 22 |
void rist_ref_inc(struct rist_ref *ref) |
| 23 |
{ |
| 24 |
atomic_fetch_add(&ref->refcnt, 1); |
| 25 |
} |
| 26 |
|
| 27 |
bool rist_ref_iswritable(struct rist_ref *ref) |
| 28 |
{ |
| 29 |
return atomic_load(&ref->refcnt) == 1 && ref->ptr; |
| 30 |
} |