aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/compiler.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r--include/linux/compiler.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 9a528d945498..26fc8bc77f85 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -252,7 +252,23 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
252 ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) 252 ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
253 253
254#define WRITE_ONCE(x, val) \ 254#define WRITE_ONCE(x, val) \
255 ({ typeof(x) __val = (val); __write_once_size(&(x), &__val, sizeof(__val)); __val; }) 255 ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; })
256
257/**
258 * READ_ONCE_CTRL - Read a value heading a control dependency
259 * @x: The value to be read, heading the control dependency
260 *
261 * Control dependencies are tricky. See Documentation/memory-barriers.txt
262 * for important information on how to use them. Note that in many cases,
263 * use of smp_load_acquire() will be much simpler. Control dependencies
264 * should be avoided except on the hottest of hotpaths.
265 */
266#define READ_ONCE_CTRL(x) \
267({ \
268 typeof(x) __val = READ_ONCE(x); \
269 smp_read_barrier_depends(); /* Enforce control dependency. */ \
270 __val; \
271})
256 272
257#endif /* __KERNEL__ */ 273#endif /* __KERNEL__ */
258 274
@@ -452,7 +468,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
452 * with an explicit memory barrier or atomic instruction that provides the 468 * with an explicit memory barrier or atomic instruction that provides the
453 * required ordering. 469 * required ordering.
454 * 470 *
455 * If possible use READ_ONCE/ASSIGN_ONCE instead. 471 * If possible use READ_ONCE()/WRITE_ONCE() instead.
456 */ 472 */
457#define __ACCESS_ONCE(x) ({ \ 473#define __ACCESS_ONCE(x) ({ \
458 __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \ 474 __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \