From d2b9489594cde6024626c960697a2051e23169bb Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Wed, 31 Aug 2022 03:04:45 +0400 Subject: test --- source/kit/atomic.h | 56 +++++++++++++++++-------------------- source/test/unittests/atomic.test.c | 12 +++++--- 2 files changed, 34 insertions(+), 34 deletions(-) (limited to 'source') diff --git a/source/kit/atomic.h b/source/kit/atomic.h index 98c9b0e..6ab6bee 100644 --- a/source/kit/atomic.h +++ b/source/kit/atomic.h @@ -78,33 +78,31 @@ uint64_t kit_atomic_fetch_add_explicit_64(uint64_t volatile *var, uint64_t value, int memory_order); -# define atomic_store_explicit(var_, value_, memory_order_) \ - do { \ - static_assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ - sizeof *(var_) == 4 || sizeof *(var_) == 8, \ - "Wrong atomic variable type"); \ - if (sizeof *(var_) == 1) \ - kit_atomic_store_explicit_8((uint8_t volatile *) (var_), \ - (uint8_t) (value_), \ - (memory_order_)); \ - if (sizeof *(var_) == 2) \ - kit_atomic_store_explicit_16((uint16_t volatile *) (var_), \ - (uint16_t) (value_), \ - (memory_order_)); \ - if (sizeof *(var_) == 4) \ - kit_atomic_store_explicit_32((uint32_t volatile *) (var_), \ - (uint32_t) (value_), \ - (memory_order_)); \ - if (sizeof *(var_) == 8) \ - kit_atomic_store_explicit_64((uint64_t volatile *) (var_), \ - (uint64_t) (value_), \ - (memory_order_)); \ +# define atomic_store_explicit(var_, value_, memory_order_) \ + do { \ + assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ + sizeof *(var_) == 4 || sizeof *(var_) == 8); \ + if (sizeof *(var_) == 1) \ + kit_atomic_store_explicit_8((uint8_t volatile *) (var_), \ + (uint8_t) (value_), \ + (memory_order_)); \ + if (sizeof *(var_) == 2) \ + kit_atomic_store_explicit_16((uint16_t volatile *) (var_), \ + (uint16_t) (value_), \ + (memory_order_)); \ + if (sizeof *(var_) == 4) \ + kit_atomic_store_explicit_32((uint32_t volatile *) (var_), \ + (uint32_t) (value_), \ + (memory_order_)); \ + if (sizeof *(var_) == 8) \ + kit_atomic_store_explicit_64((uint64_t volatile *) (var_), \ + (uint64_t) (value_), \ + (memory_order_)); \ } while (0) # define atomic_load_explicit(var_, memory_order_) \ - (static_assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ - sizeof *(var_) == 4 || sizeof *(var_) == 8, \ - "Wrong atomic variable type"), \ + (assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ + sizeof *(var_) == 4 || sizeof *(var_) == 8), \ (sizeof *(var_) == 1 \ ? kit_atomic_load_explicit_8((uint8_t volatile *) (var_), \ (value_), (memory_order_)) \ @@ -119,9 +117,8 @@ uint64_t kit_atomic_fetch_add_explicit_64(uint64_t volatile *var, (value_), (memory_order_)))) # define atomic_exchange_explicit(var_, value_, memory_order_) \ - (static_assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ - sizeof *(var_) == 4 || sizeof *(var_) == 8, \ - "Wrong atomic variable type"), \ + (assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ + sizeof *(var_) == 4 || sizeof *(var_) == 8), \ (sizeof *(var_) == 1 ? kit_atomic_exchange_explicit_8( \ (uint8_t volatile *) (var_), \ (uint8_t) (value_), (memory_order_)) \ @@ -138,9 +135,8 @@ uint64_t kit_atomic_fetch_add_explicit_64(uint64_t volatile *var, (memory_order_)))) # define atomic_fetch_add_explicit(var_, value_, memory_order_) \ - (static_assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ - sizeof *(var_) == 4 || sizeof *(var_) == 8, \ - "Wrong atomic variable type"), \ + (assert(sizeof *(var_) == 1 || sizeof *(var_) == 2 || \ + sizeof *(var_) == 4 || sizeof *(var_) == 8), \ (sizeof *(var_) == 1 ? kit_atomic_fetch_add_explicit_8( \ (uint8_t volatile *) (var_), \ (uint8_t) (value_), (memory_order_)) \ diff --git a/source/test/unittests/atomic.test.c b/source/test/unittests/atomic.test.c index 8f6d22b..24cadca 100644 --- a/source/test/unittests/atomic.test.c +++ b/source/test/unittests/atomic.test.c @@ -83,7 +83,8 @@ TEST("atomic byte concurrency") { thrd_t threads[THREAD_COUNT]; for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) - thrd_create(threads + i, test_8_, (i % 2) ? &foo : &bar); + thrd_create(threads + i, test_8_, + (void *) ((i % 2) ? &foo : &bar)); for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); @@ -113,7 +114,8 @@ TEST("atomic int16 concurrency") { thrd_t threads[THREAD_COUNT]; for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) - thrd_create(threads + i, test_16_, (i % 2) ? &foo : &bar); + thrd_create(threads + i, test_16_, + (void *) ((i % 2) ? &foo : &bar)); for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); @@ -143,7 +145,8 @@ TEST("atomic int32 concurrency") { thrd_t threads[THREAD_COUNT]; for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) - thrd_create(threads + i, test_32_, (i % 2) ? &foo : &bar); + thrd_create(threads + i, test_32_, + (void *) ((i % 2) ? &foo : &bar)); for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); @@ -176,7 +179,8 @@ TEST("atomic int64 concurrency") { thrd_t threads[THREAD_COUNT]; for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) - thrd_create(threads + i, test_64_, (i % 2) ? &foo : &bar); + thrd_create(threads + i, test_64_, + (void *) ((i % 2) ? &foo : &bar)); for (ptrdiff_t i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL); -- cgit v1.2.3