Cleanup: Move instrumentation/ headers to include/instrumentation/
[lttng-modules.git] / wrapper / kref.h
CommitLineData
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>
77932315 19#include <linux/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 */
77932315
FD
26#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0))
27static 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)) */
9c1f4643
MD
33static inline int lttng_kref_get(struct kref *kref)
34{
4c4d77da 35 return atomic_add_unless(&kref->refcount, 1, INT_MAX);
9c1f4643 36}
77932315 37#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0)) */
9c1f4643
MD
38
39#endif /* _LTTNG_WRAPPER_KREF_H */
This page took 0.030492 seconds and 4 git commands to generate.