Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: GPL-2.0-only |
9f36eaed | 2 | * |
9c1f4643 MD |
3 | * wrapper/kref.h |
4 | * | |
5 | * wrapper around linux/kref.h. | |
6 | * | |
7 | * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * | |
9c1f4643 MD |
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 | ||
9f36eaed MJ |
14 | #ifndef _LTTNG_WRAPPER_KREF_H |
15 | #define _LTTNG_WRAPPER_KREF_H | |
16 | ||
9c1f4643 MD |
17 | #include <linux/kref.h> |
18 | #include <linux/rculist.h> | |
5f4c791e | 19 | #include <lttng/kernel-version.h> |
9c1f4643 MD |
20 | |
21 | /* | |
22 | * lttng_kref_get: get reference count, checking for overflow. | |
23 | * | |
24 | * Return 1 if reference is taken, 0 otherwise (overflow). | |
25 | */ | |
5f4c791e | 26 | #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) |
77932315 FD |
27 | static inline int lttng_kref_get(struct kref *kref) |
28 | { | |
29 | kref_get(kref); | |
30 | return 1; | |
31 | } | |
5f4c791e | 32 | #else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */ |
9c1f4643 MD |
33 | static inline int lttng_kref_get(struct kref *kref) |
34 | { | |
4c4d77da | 35 | return atomic_add_unless(&kref->refcount, 1, INT_MAX); |
9c1f4643 | 36 | } |
5f4c791e | 37 | #endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */ |
9c1f4643 MD |
38 | |
39 | #endif /* _LTTNG_WRAPPER_KREF_H */ |