Cleanup: Move wrapper/ headers to include/wrapper/
[lttng-modules.git] / include / wrapper / kref.h
1 /* SPDX-License-Identifier: GPL-2.0-only
2 *
3 * wrapper/kref.h
4 *
5 * wrapper around linux/kref.h.
6 *
7 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 *
9 * This wrapper code is derived from Linux 3.19.2 include/linux/list.h
10 * and include/linux/rculist.h, hence the GPLv2 license applied to this
11 * file.
12 */
13
14 #ifndef _LTTNG_WRAPPER_KREF_H
15 #define _LTTNG_WRAPPER_KREF_H
16
17 #include <linux/kref.h>
18 #include <linux/rculist.h>
19 #include <linux/version.h>
20
21 /*
22 * lttng_kref_get: get reference count, checking for overflow.
23 *
24 * Return 1 if reference is taken, 0 otherwise (overflow).
25 */
26 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
27 static inline int lttng_kref_get(struct kref *kref)
28 {
29 kref_get(kref);
30 return 1;
31 }
32 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
33 static inline int lttng_kref_get(struct kref *kref)
34 {
35 return atomic_add_unless(&kref->refcount, 1, INT_MAX);
36 }
37 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
38
39 #endif /* _LTTNG_WRAPPER_KREF_H */
This page took 0.031382 seconds and 4 git commands to generate.