kernel: Add token field to `struct lttng_kernel_event`
[lttng-tools.git] / include / lttng / ref-internal.h
CommitLineData
8abe313a
JG
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 *
ab5be9fa 9 * SPDX-License-Identifier: LGPL-2.1-only
8abe313a 10 *
8abe313a
JG
11 */
12
13#include <assert.h>
14
15typedef void (*lttng_release_func)(void *);
16
17struct lttng_ref {
18 unsigned long count;
19 lttng_release_func release;
20};
21
22static inline
23void lttng_ref_init(struct lttng_ref *ref, lttng_release_func release)
24{
25 assert(ref);
26 ref->count = 1;
27 ref->release = release;
28}
29
30static inline
31void lttng_ref_get(struct lttng_ref *ref)
32{
33 assert(ref);
34 ref->count++;
35 /* Overflow check. */
36 assert(ref->count);
37}
38
39static inline
40void lttng_ref_put(struct lttng_ref *ref)
41{
42 assert(ref);
43 /* Underflow check. */
44 assert(ref->count);
45 if (caa_unlikely((--ref->count) == 0)) {
46 ref->release(ref);
47 }
48}
49
50#endif /* LTTNG_REF_INTERNAL_H */
This page took 0.030431 seconds and 4 git commands to generate.