compiler.h: add READ_ONCE/WRITE_ONCE macro

These macros are needed to make sure the compiler does not optimize away
atomic constructs such as "while (!READ_ONCE(foo))" loops that do not
modify foo within the loop

Also move the barrier() define where it belongs while we are here, it is
needed for READ_ONCE/WRITE_ONCE and including ihk/cpu.h here causes
include loops

Change-Id: Ia533a849ed674719ccbc0495be47d22a3c47b8f8
This commit is contained in:
Dominique Martinet
2018-09-21 12:30:52 +09:00
committed by Masamichi Takagi
parent 13e71ac9dc
commit 3e3ccf377c
6 changed files with 65 additions and 13 deletions

View File

@ -12,11 +12,8 @@
/* Optimization barrier */
/* The "volatile" is due to gcc bugs */
/* XXX: barrier is also defined in lib/include/ihk/cpu.h,
* it would be cleaner to restore this here at some point, but we have
* quite a few C files not including either this or kernel's compiler.h
* #define barrier() __asm__ __volatile__("": : :"memory")
*/
#define barrier() __asm__ __volatile__("": : :"memory")
/*
* This version is i.e. to prevent dead stores elimination on @ptr
* where gcc and llvm may behave differently when otherwise using