Introduce lttng smp_store_release smp_load_acquire wrappers
[lttng-modules.git] / include / wrapper / barrier.h
1 /* SPDX-License-Identifier: GPL-2.0-only
2 *
3 * wrapper/barrier.h
4 *
5 * wrapper around asm/barrier.h.
6 *
7 * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #ifndef _LTTNG_WRAPPER_BARRIER_H
11 #define _LTTNG_WRAPPER_BARRIER_H
12
13 #include <linux/version.h>
14 #include <asm/barrier.h>
15
16 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
17
18 #define lttng_smp_store_release(x, v) smp_store_release(x, v)
19 #define lttng_smp_load_acquire(x) smp_load_acquire(x)
20
21 #else
22
23 /*
24 * Acquire-release semantics act as a one-way permeable barrier when
25 * pairing a store with a release. Use a full memory barrier to emulate
26 * the acquire-release semantic with a stronger barrier on older
27 * kernels.
28 */
29
30 #define lttng_smp_store_release(x, v) \
31 do { \
32 smp_mb(); \
33 ACCESS_ONCE(*(x)) = (v); \
34 } while (0)
35
36 #define lttng_smp_load_acquire(x) \
37 ({ \
38 __typeof__(*(x)) ___ret; \
39 \
40 ___ret = ACCESS_ONCE(*(x)); \
41 smp_mb(); \
42 ___ret; \
43 })
44
45 #endif
46
47 #endif /* _LTTNG_WRAPPER_BARRIER_H */
This page took 0.029367 seconds and 4 git commands to generate.