mirror of
git://repo.or.cz/tinycc.git
synced 2026-11-05 05:36:35 +08:00
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-arm64-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
build and test / test-i386-linux (push) Has been cancelled
- remove the non-atomic write and repeated argument evaluation from __atomic_store_n - remove the recursive atomic_signal_fence macro - add tests for stores and signal fences tested with make test on linux x86_64
46 lines
1.2 KiB
C
46 lines
1.2 KiB
C
#include <stdatomic.h>
|
|
#include <stdio.h>
|
|
|
|
static int value_calls;
|
|
static int order_calls;
|
|
|
|
static int next_value(void)
|
|
{
|
|
++value_calls;
|
|
return 42;
|
|
}
|
|
|
|
static int next_order(void)
|
|
{
|
|
++order_calls;
|
|
return __ATOMIC_SEQ_CST;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
int values[2] = {7, 8};
|
|
int index = 0;
|
|
int value = 1;
|
|
volatile int vol = 0;
|
|
int *pointer = &value;
|
|
void (*signal_fence)(memory_order) = &atomic_signal_fence;
|
|
|
|
__atomic_store_n(&values[index++], next_value(), next_order());
|
|
printf("%d %d %d %d %d\n", index, value_calls, order_calls,
|
|
values[0], values[1]);
|
|
__atomic_store_n(&value, value + 1, __ATOMIC_RELAXED);
|
|
printf("%d\n", value);
|
|
__atomic_store_n(&vol, 13, __ATOMIC_RELEASE);
|
|
printf("%d\n", __atomic_load_n(&vol, __ATOMIC_ACQUIRE));
|
|
__atomic_store_n(&pointer, &values[0], __ATOMIC_RELEASE);
|
|
printf("%d\n", *__atomic_load_n(&pointer, __ATOMIC_ACQUIRE));
|
|
|
|
atomic_signal_fence(memory_order_acquire);
|
|
__atomic_signal_fence(__ATOMIC_RELEASE);
|
|
signal_fence(memory_order_seq_cst);
|
|
atomic_thread_fence(memory_order_seq_cst);
|
|
__atomic_thread_fence(__ATOMIC_SEQ_CST);
|
|
puts("ok");
|
|
return 0;
|
|
}
|