kernel: define READ/WRITE_ONCE using typeof() for C sources
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
#ifndef SOCKS_COMPILER_H_
|
||||
#define SOCKS_COMPILER_H_
|
||||
|
||||
#define READ_ONCE(t, p) (*((const volatile t *)&(p)))
|
||||
#define WRITE_ONCE(t, p, v) *(volatile t *)&(p) = (v)
|
||||
|
||||
#ifdef __cplusplus
|
||||
template <typename T>
|
||||
T read_once(const volatile T *ptr)
|
||||
@@ -16,6 +13,11 @@ void write_once(volatile T *ptr, T value)
|
||||
{
|
||||
*ptr = value;
|
||||
}
|
||||
#else
|
||||
|
||||
#define READ_ONCE(p) (*((const volatile typeof(p) *)&(p)))
|
||||
#define WRITE_ONCE(p, v) *(volatile typeof(p) *)&(p) = (v)
|
||||
|
||||
#endif
|
||||
|
||||
#undef __used
|
||||
|
||||
Reference in New Issue
Block a user