summaryrefslogtreecommitdiff
path: root/source/tests/atomic.test.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/tests/atomic.test.c')
-rw-r--r--source/tests/atomic.test.c77
1 files changed, 40 insertions, 37 deletions
diff --git a/source/tests/atomic.test.c b/source/tests/atomic.test.c
index d5c172b..ca14959 100644
--- a/source/tests/atomic.test.c
+++ b/source/tests/atomic.test.c
@@ -5,13 +5,13 @@
#include "../kit/test.h"
TEST("atomic store and load") {
- ATOMIC(int) value;
+ int _Atomic value;
atomic_store_explicit(&value, 20, memory_order_relaxed);
REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 20);
}
TEST("atomic exchange") {
- ATOMIC(int) value;
+ int _Atomic value;
atomic_store_explicit(&value, 20, memory_order_relaxed);
REQUIRE(atomic_exchange_explicit(&value, 42,
memory_order_relaxed) == 20);
@@ -19,20 +19,23 @@ TEST("atomic exchange") {
}
TEST("atomic fetch add") {
- ATOMIC(int) value;
+ int _Atomic value;
atomic_store_explicit(&value, 20, memory_order_relaxed);
REQUIRE(atomic_fetch_add_explicit(&value, 22,
memory_order_relaxed) == 20);
REQUIRE(atomic_load_explicit(&value, memory_order_relaxed) == 42);
}
-enum { THREAD_COUNT = 20, TICK_COUNT = 10000 };
+enum {
+ TEST_ATOMIC_THREAD_COUNT = 20,
+ TEST_ATOMIC_TICK_COUNT = 10000,
+};
static int test_8_(void *p) {
ptrdiff_t i;
- ATOMIC(int8_t) *x = (ATOMIC(int8_t) *) p;
+ int8_t _Atomic *x = (int8_t _Atomic *) p;
- for (i = 0; i < TICK_COUNT; i++) {
+ for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) {
atomic_fetch_add_explicit(x, 20, memory_order_relaxed);
thrd_yield();
atomic_fetch_add_explicit(x, 22, memory_order_relaxed);
@@ -45,11 +48,11 @@ static int test_8_(void *p) {
}
TEST("atomic types") {
- ATOMIC(int8_t) b_1;
- ATOMIC(int8_t) b_2;
- ATOMIC(int16_t) i16;
- ATOMIC(int32_t) i32;
- ATOMIC(int64_t) i64;
+ int8_t _Atomic b_1;
+ int8_t _Atomic b_2;
+ int16_t _Atomic i16;
+ int32_t _Atomic i32;
+ int64_t _Atomic i64;
atomic_store_explicit(&b_1, 42, memory_order_relaxed);
atomic_store_explicit(&b_2, 43, memory_order_relaxed);
@@ -86,18 +89,18 @@ TEST("atomic types") {
TEST("atomic byte concurrency") {
ptrdiff_t i;
- ATOMIC(int8_t) foo;
- ATOMIC(int8_t) bar;
+ int8_t _Atomic foo;
+ int8_t _Atomic bar;
atomic_store_explicit(&foo, 42, memory_order_relaxed);
atomic_store_explicit(&bar, 43, memory_order_relaxed);
- thrd_t threads[THREAD_COUNT];
- for (i = 0; i < THREAD_COUNT; i++)
+ thrd_t threads[TEST_ATOMIC_THREAD_COUNT];
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++)
REQUIRE_EQ(thrd_create(threads + i, test_8_,
(void *) ((i % 2) ? &foo : &bar)),
thrd_success);
- for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL);
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL);
REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42);
REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43);
@@ -106,9 +109,9 @@ TEST("atomic byte concurrency") {
static int test_16_(void *p) {
ptrdiff_t i;
- ATOMIC(int16_t) *x = (ATOMIC(int16_t) *) p;
+ int16_t _Atomic *x = (int16_t _Atomic *) p;
- for (i = 0; i < TICK_COUNT; i++) {
+ for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) {
atomic_fetch_add_explicit(x, 2020, memory_order_relaxed);
thrd_yield();
atomic_fetch_add_explicit(x, 2222, memory_order_relaxed);
@@ -123,18 +126,18 @@ static int test_16_(void *p) {
TEST("atomic int16 concurrency") {
ptrdiff_t i;
- ATOMIC(int16_t) foo;
- ATOMIC(int16_t) bar;
+ int16_t _Atomic foo;
+ int16_t _Atomic bar;
atomic_store_explicit(&foo, 42, memory_order_relaxed);
atomic_store_explicit(&bar, 43, memory_order_relaxed);
- thrd_t threads[THREAD_COUNT];
- for (i = 0; i < THREAD_COUNT; i++)
+ thrd_t threads[TEST_ATOMIC_THREAD_COUNT];
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++)
REQUIRE_EQ(thrd_create(threads + i, test_16_,
(void *) ((i % 2) ? &foo : &bar)),
thrd_success);
- for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL);
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL);
REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42);
REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43);
@@ -143,9 +146,9 @@ TEST("atomic int16 concurrency") {
static int test_32_(void *p) {
ptrdiff_t i;
- ATOMIC(int32_t) *x = (ATOMIC(int32_t) *) p;
+ int32_t _Atomic *x = (int32_t _Atomic *) p;
- for (i = 0; i < TICK_COUNT; i++) {
+ for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) {
atomic_fetch_add_explicit(x, 202020, memory_order_relaxed);
thrd_yield();
atomic_fetch_add_explicit(x, 222222, memory_order_relaxed);
@@ -160,18 +163,18 @@ static int test_32_(void *p) {
TEST("atomic int32 concurrency") {
ptrdiff_t i;
- ATOMIC(int32_t) foo;
- ATOMIC(int32_t) bar;
+ int32_t _Atomic foo;
+ int32_t _Atomic bar;
atomic_store_explicit(&foo, 42, memory_order_relaxed);
atomic_store_explicit(&bar, 43, memory_order_relaxed);
- thrd_t threads[THREAD_COUNT];
- for (i = 0; i < THREAD_COUNT; i++)
+ thrd_t threads[TEST_ATOMIC_THREAD_COUNT];
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++)
REQUIRE_EQ(thrd_create(threads + i, test_32_,
(void *) ((i % 2) ? &foo : &bar)),
thrd_success);
- for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL);
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL);
REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42);
REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43);
@@ -180,9 +183,9 @@ TEST("atomic int32 concurrency") {
static int test_64_(void *p) {
ptrdiff_t i;
- ATOMIC(int64_t) *x = (ATOMIC(int64_t) *) p;
+ int64_t _Atomic *x = (int64_t _Atomic *) p;
- for (i = 0; i < TICK_COUNT; i++) {
+ for (i = 0; i < TEST_ATOMIC_TICK_COUNT; i++) {
atomic_fetch_add_explicit(x, 20202020202020ll,
memory_order_relaxed);
thrd_yield();
@@ -200,18 +203,18 @@ static int test_64_(void *p) {
TEST("atomic int64 concurrency") {
ptrdiff_t i;
- ATOMIC(int64_t) foo;
- ATOMIC(int64_t) bar;
+ int64_t _Atomic foo;
+ int64_t _Atomic bar;
atomic_store_explicit(&foo, 42, memory_order_relaxed);
atomic_store_explicit(&bar, 43, memory_order_relaxed);
- thrd_t threads[THREAD_COUNT];
- for (i = 0; i < THREAD_COUNT; i++)
+ thrd_t threads[TEST_ATOMIC_THREAD_COUNT];
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++)
REQUIRE_EQ(thrd_create(threads + i, test_64_,
(void *) ((i % 2) ? &foo : &bar)),
thrd_success);
- for (i = 0; i < THREAD_COUNT; i++) thrd_join(threads[i], NULL);
+ for (i = 0; i < TEST_ATOMIC_THREAD_COUNT; i++) thrd_join(threads[i], NULL);
REQUIRE(atomic_load_explicit(&foo, memory_order_relaxed) == 42);
REQUIRE(atomic_load_explicit(&bar, memory_order_relaxed) == 43);