File: kref.h

package info (click to toggle)
lttng-modules 2.14.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,808 kB
  • sloc: ansic: 74,851; sh: 548; makefile: 62
file content (39 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* SPDX-License-Identifier: GPL-2.0-only
 *
 * wrapper/kref.h
 *
 * wrapper around linux/kref.h.
 *
 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
 *
 * This wrapper code is derived from Linux 3.19.2 include/linux/list.h
 * and include/linux/rculist.h, hence the GPLv2 license applied to this
 * file.
 */

#ifndef _LTTNG_WRAPPER_KREF_H
#define _LTTNG_WRAPPER_KREF_H

#include <linux/kref.h>
#include <linux/rculist.h>
#include <lttng/kernel-version.h>

/*
 * lttng_kref_get: get reference count, checking for overflow.
 *
 * Return 1 if reference is taken, 0 otherwise (overflow).
 */
#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0))
static inline int lttng_kref_get(struct kref *kref)
{
	kref_get(kref);
	return 1;
}
#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */
static inline int lttng_kref_get(struct kref *kref)
{
	return atomic_add_unless(&kref->refcount, 1, INT_MAX);
}
#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,11,0)) */

#endif /* _LTTNG_WRAPPER_KREF_H */