Debian Codegraph @

src/rist_ref.c

raw symbols SCIP
1 /* librist. Copyright © 2020 SipRadius LLC. All right reserved.
2 * Author: Gijs Peskens <[email protected]>
3 * Author: Sergio Ammirata, Ph.D. <[email protected]>
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
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 }