From 6db96533770510f9ee6c4c0447f11cb7bf7cf797 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Fri, 18 Mar 2022 18:46:10 +0100 Subject: [PATCH] rwonce.h: indent; bits.h: remove useless convenience signed types --- c/bits.h | 9 ++++-- c/rwonce.h | 84 +++++++++++++++++++++++++++--------------------------- 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/c/bits.h b/c/bits.h index 322d2cb..a074010 100644 --- a/c/bits.h +++ b/c/bits.h @@ -29,6 +29,8 @@ #error "Only 64 bits word size supported." #endif +/* fixed-size types + */ typedef int64_t s64; typedef int32_t s32; typedef int16_t s16; @@ -39,14 +41,15 @@ typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8; +/* convenience types + */ typedef unsigned long int ulong; typedef unsigned int uint; typedef unsigned short ushort; typedef unsigned char uchar; -typedef signed long int slong; -typedef signed int sint; -typedef signed short sshort; +/* char is a special case, as it can be signed or unsigned + */ typedef signed char schar; /* count trailing zeroes : 00101000 -> 3 diff --git a/c/rwonce.h b/c/rwonce.h index 37021c3..d21656b 100644 --- a/c/rwonce.h +++ b/c/rwonce.h @@ -30,44 +30,44 @@ /************ originally in */ /* * __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' * is not type-compatible with 'signed char', and we define a separate case. */ -#define __scalar_type_to_expr_cases(type) \ - unsigned type: (unsigned type)0, \ - signed type: (signed type)0 +#define __scalar_type_to_expr_cases(type) \ + unsigned type: (unsigned type)0, \ + signed type: (signed type)0 -#define __unqual_scalar_typeof(x) typeof( \ - _Generic((x), \ - char: (char)0, \ - __scalar_type_to_expr_cases(char), \ - __scalar_type_to_expr_cases(short), \ - __scalar_type_to_expr_cases(int), \ - __scalar_type_to_expr_cases(long), \ - __scalar_type_to_expr_cases(long long), \ - default: (x))) +#define __unqual_scalar_typeof(x) \ + typeof(_Generic((x), \ + char: (char)0, \ + __scalar_type_to_expr_cases(char), \ + __scalar_type_to_expr_cases(short), \ + __scalar_type_to_expr_cases(int), \ + __scalar_type_to_expr_cases(long), \ + __scalar_type_to_expr_cases(long long), \ + default: (x))) /* Is this type a native word size -- useful for atomic operations */ #define __native_word(t) \ - (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ - sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) + (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || \ + sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) #ifdef __OPTIMIZE__ -# define __compiletime_assert(condition, msg, prefix, suffix) \ - do { \ - extern void prefix ## suffix(void) __compiletime_error(msg); \ - if (!(condition)) \ - prefix ## suffix(); \ - } while (0) +# define __compiletime_assert(condition, msg, prefix, suffix) \ + do { \ + extern void prefix ## suffix(void) __compiletime_error(msg); \ + if (!(condition)) \ + prefix ## suffix(); \ + } while (0) #else # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0) #endif #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 @@ -78,12 +78,12 @@ * supplied condition is *false*, emitting the supplied error message if the * compiler has support to do so. */ -#define compiletime_assert(condition, msg) \ - _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) +#define compiletime_assert(condition, msg) \ + _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__) -#define compiletime_assert_atomic_type(t) \ - compiletime_assert(__native_word(t), \ - "Need native word sized stores/loads for atomicity.") +#define compiletime_assert_atomic_type(t) \ + compiletime_assert(__native_word(t), \ + "Need native word sized stores/loads for atomicity.") /************ originally in */ /* @@ -92,33 +92,33 @@ * 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. */ -#define compiletime_assert_rwonce_type(t) \ - compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \ - "Unsupported access size for {READ,WRITE}_ONCE().") +#define compiletime_assert_rwonce_type(t) \ + compiletime_assert(__native_word(t) || sizeof(t) == sizeof(long long), \ + "Unsupported access size for {READ,WRITE}_ONCE().") /* * 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 __unqual_scalar_typeof(x) *)&(x)) +#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x)) #endif -#define READ_ONCE(x) \ -({ \ - compiletime_assert_rwonce_type(x); \ - __READ_ONCE(x); \ +#define READ_ONCE(x) \ +({ \ + compiletime_assert_rwonce_type(x); \ + __READ_ONCE(x); \ }) -#define __WRITE_ONCE(x, val) \ -do { \ - *(volatile typeof(x) *)&(x) = (val); \ +#define __WRITE_ONCE(x, val) \ +do { \ + *(volatile typeof(x) *)&(x) = (val); \ } while (0) -#define WRITE_ONCE(x, val) \ -do { \ - compiletime_assert_rwonce_type(x); \ - __WRITE_ONCE(x, val); \ +#define WRITE_ONCE(x, val) \ +do { \ + compiletime_assert_rwonce_type(x); \ + __WRITE_ONCE(x, val); \ } while (0) #endif /* __BR_RWONCE_H */