rwonce.h: indent; bits.h: remove useless convenience signed types

This commit is contained in:
2022-03-18 18:46:10 +01:00
parent a92a4e04b4
commit 6db9653377
2 changed files with 48 additions and 45 deletions

View File

@@ -29,6 +29,8 @@
#error "Only 64 bits word size supported." #error "Only 64 bits word size supported."
#endif #endif
/* fixed-size types
*/
typedef int64_t s64; typedef int64_t s64;
typedef int32_t s32; typedef int32_t s32;
typedef int16_t s16; typedef int16_t s16;
@@ -39,14 +41,15 @@ typedef uint32_t u32;
typedef uint16_t u16; typedef uint16_t u16;
typedef uint8_t u8; typedef uint8_t u8;
/* convenience types
*/
typedef unsigned long int ulong; typedef unsigned long int ulong;
typedef unsigned int uint; typedef unsigned int uint;
typedef unsigned short ushort; typedef unsigned short ushort;
typedef unsigned char uchar; typedef unsigned char uchar;
typedef signed long int slong; /* char is a special case, as it can be signed or unsigned
typedef signed int sint; */
typedef signed short sshort;
typedef signed char schar; typedef signed char schar;
/* count trailing zeroes : 00101000 -> 3 /* count trailing zeroes : 00101000 -> 3

View File

@@ -30,44 +30,44 @@
/************ originally in <include/linux/compiler_types.h> */ /************ originally in <include/linux/compiler_types.h> */
/* /*
* __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving
* non-scalar types unchanged. * non-scalar types unchanged.
*/ */
/* /*
* Prefer C11 _Generic for better compile-times and simpler code. Note: 'char' * Prefer C11 _Generic for better compile-times and simpler code. Note: 'char'
* is not type-compatible with 'signed char', and we define a separate case. * is not type-compatible with 'signed char', and we define a separate case.
*/ */
#define __scalar_type_to_expr_cases(type) \ #define __scalar_type_to_expr_cases(type) \
unsigned type: (unsigned type)0, \ unsigned type: (unsigned type)0, \
signed type: (signed type)0 signed type: (signed type)0
#define __unqual_scalar_typeof(x) typeof( \ #define __unqual_scalar_typeof(x) \
_Generic((x), \ typeof(_Generic((x), \
char: (char)0, \ char: (char)0, \
__scalar_type_to_expr_cases(char), \ __scalar_type_to_expr_cases(char), \
__scalar_type_to_expr_cases(short), \ __scalar_type_to_expr_cases(short), \
__scalar_type_to_expr_cases(int), \ __scalar_type_to_expr_cases(int), \
__scalar_type_to_expr_cases(long), \ __scalar_type_to_expr_cases(long), \
__scalar_type_to_expr_cases(long long), \ __scalar_type_to_expr_cases(long long), \
default: (x))) default: (x)))
/* Is this type a native word size -- useful for atomic operations */ /* Is this type a native word size -- useful for atomic operations */
#define __native_word(t) \ #define __native_word(t) \
(sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \
sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
#ifdef __OPTIMIZE__ #ifdef __OPTIMIZE__
# define __compiletime_assert(condition, msg, prefix, suffix) \ # define __compiletime_assert(condition, msg, prefix, suffix) \
do { \ do { \
extern void prefix ## suffix(void) __compiletime_error(msg); \ extern void prefix ## suffix(void) __compiletime_error(msg); \
if (!(condition)) \ if (!(condition)) \
prefix ## suffix(); \ prefix ## suffix(); \
} while (0) } while (0)
#else #else
# define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)
#endif #endif
#define _compiletime_assert(condition, msg, prefix, suffix) \ #define _compiletime_assert(condition, msg, prefix, suffix) \
__compiletime_assert(condition, msg, prefix, suffix) __compiletime_assert(condition, msg, prefix, suffix)
/** /**
* compiletime_assert - break build and emit msg if condition is false * compiletime_assert - break build and emit msg if condition is false
@@ -78,12 +78,12 @@
* supplied condition is *false*, emitting the supplied error message if the * supplied condition is *false*, emitting the supplied error message if the
* compiler has support to do so. * compiler has support to do so.
*/ */
#define compiletime_assert(condition, msg) \ #define compiletime_assert(condition, msg) \
_compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
#define compiletime_assert_atomic_type(t) \ #define compiletime_assert_atomic_type(t) \
compiletime_assert(__native_word(t), \ compiletime_assert(__native_word(t), \
"Need native word sized stores/loads for atomicity.") "Need native word sized stores/loads for atomicity.")
/************ originally in <asm-generic/rwonce.h> */ /************ originally in <asm-generic/rwonce.h> */
/* /*
@@ -92,33 +92,33 @@
* rely on the access being split into 2x32-bit accesses for a 32-bit quantity * rely on the access being split into 2x32-bit accesses for a 32-bit quantity
* (e.g. a virtual address) and a strong prevailing wind. * (e.g. a virtual address) and a strong prevailing wind.
*/ */
#define compiletime_assert_rwonce_type(t) \ #define compiletime_assert_rwonce_type(t) \
compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \ compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \
"Unsupported access size for {READ,WRITE}_ONCE().") "Unsupported access size for {READ,WRITE}_ONCE().")
/* /*
* Use __READ_ONCE() instead of READ_ONCE() if you do not require any * Use __READ_ONCE() instead of READ_ONCE() if you do not require any
* atomicity. Note that this may result in tears! * atomicity. Note that this may result in tears!
*/ */
#ifndef __READ_ONCE #ifndef __READ_ONCE
#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x)) #define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
#endif #endif
#define READ_ONCE(x) \ #define READ_ONCE(x) \
({ \ ({ \
compiletime_assert_rwonce_type(x); \ compiletime_assert_rwonce_type(x); \
__READ_ONCE(x); \ __READ_ONCE(x); \
}) })
#define __WRITE_ONCE(x, val) \ #define __WRITE_ONCE(x, val) \
do { \ do { \
*(volatile typeof(x) *)&(x) = (val); \ *(volatile typeof(x) *)&(x) = (val); \
} while (0) } while (0)
#define WRITE_ONCE(x, val) \ #define WRITE_ONCE(x, val) \
do { \ do { \
compiletime_assert_rwonce_type(x); \ compiletime_assert_rwonce_type(x); \
__WRITE_ONCE(x, val); \ __WRITE_ONCE(x, val); \
} while (0) } while (0)
#endif /* __BR_RWONCE_H */ #endif /* __BR_RWONCE_H */