Fix: update writeback instrumentation for kernel 4.14
[lttng-modules.git] / wrapper / kref.h
CommitLineData
9c1f4643
MD
1#ifndef _LTTNG_WRAPPER_KREF_H
2#define _LTTNG_WRAPPER_KREF_H
3
4/*
5 * wrapper/kref.h
6 *
7 * wrapper around linux/kref.h.
8 *
9 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; only version 2 of the License.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 * This wrapper code is derived from Linux 3.19.2 include/linux/list.h
25 * and include/linux/rculist.h, hence the GPLv2 license applied to this
26 * file.
27 */
28
29#include <linux/kref.h>
30#include <linux/rculist.h>
77932315 31#include <linux/version.h>
9c1f4643
MD
32
33/*
34 * lttng_kref_get: get reference count, checking for overflow.
35 *
36 * Return 1 if reference is taken, 0 otherwise (overflow).
37 */
77932315
FD
38#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
39static inline int lttng_kref_get(struct kref *kref)
40{
41 kref_get(kref);
42 return 1;
43}
44#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
9c1f4643
MD
45static inline int lttng_kref_get(struct kref *kref)
46{
4c4d77da 47 return atomic_add_unless(&kref->refcount, 1, INT_MAX);
9c1f4643 48}
77932315 49#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
9c1f4643
MD
50
51#endif /* _LTTNG_WRAPPER_KREF_H */
This page took 0.026433 seconds and 4 git commands to generate.