kernel: define READ/WRITE_ONCE using typeof() for C sources

This commit is contained in:
2023-03-27 22:00:30 +01:00
parent e1634de1b4
commit 8de86c210f

View File

@@ -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