btrfs-progs: kernel-lib: add simplified READ_ONCE and WRITE_ONCE
For easier source synchronization with kernel, add the _ONCE wrappers, but only the simplified version as we don't do any lock-less algorithms or use the semantics in userspace. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
c1b24d742f
commit
2b603d9819
32
kerncompat.h
32
kerncompat.h
|
@ -531,4 +531,36 @@ struct __una_u64 { __le64 x; } __attribute__((__packed__));
|
|||
#define noinline
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note: simplified versions of READ_ONCE and WRITE_ONCE for source
|
||||
* compatibility only, not usable for lock-less implementation like in kernel.
|
||||
*
|
||||
* Changed:
|
||||
* - __unqual_scalar_typeof: volatile cast to typeof()
|
||||
* - compiletime_assert_rwonce_type: no word size compatibility checks
|
||||
*/
|
||||
|
||||
/*
|
||||
* Use __READ_ONCE() instead of READ_ONCE() if you do not require any
|
||||
* atomicity. Note that this may result in tears!
|
||||
*/
|
||||
#ifndef __READ_ONCE
|
||||
#define __READ_ONCE(x) (*(const volatile typeof(x) *)&(x))
|
||||
#endif
|
||||
|
||||
#define READ_ONCE(x) \
|
||||
({ \
|
||||
__READ_ONCE(x); \
|
||||
})
|
||||
|
||||
#define __WRITE_ONCE(x, val) \
|
||||
do { \
|
||||
*(volatile typeof(x) *)&(x) = (val); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE_ONCE(x, val) \
|
||||
do { \
|
||||
__WRITE_ONCE(x, val); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue