Add a basic .clang-tidy file and fix typedef warnings
[lttng-tools.git] / include / lttng / ref-internal.hpp
1 #ifndef LTTNG_REF_INTERNAL_H
2 #define LTTNG_REF_INTERNAL_H
3
4 /*
5 * LTTng - Non thread-safe reference counting
6 *
7 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 *
9 * SPDX-License-Identifier: LGPL-2.1-only
10 *
11 */
12
13 using lttng_release_func = void (*)(void *);
14
15 struct lttng_ref {
16 unsigned long count;
17 lttng_release_func release;
18 };
19
20 static inline
21 void lttng_ref_init(struct lttng_ref *ref, lttng_release_func release)
22 {
23 LTTNG_ASSERT(ref);
24 ref->count = 1;
25 ref->release = release;
26 }
27
28 static inline
29 void lttng_ref_get(struct lttng_ref *ref)
30 {
31 LTTNG_ASSERT(ref);
32 ref->count++;
33 /* Overflow check. */
34 LTTNG_ASSERT(ref->count);
35 }
36
37 static inline
38 void lttng_ref_put(struct lttng_ref *ref)
39 {
40 LTTNG_ASSERT(ref);
41 /* Underflow check. */
42 LTTNG_ASSERT(ref->count);
43 if (caa_unlikely((--ref->count) == 0)) {
44 ref->release(ref);
45 }
46 }
47
48 #endif /* LTTNG_REF_INTERNAL_H */
This page took 0.03112 seconds and 5 git commands to generate.