mirror of
git://repo.or.cz/tinycc.git
synced 2026-11-04 21:26:36 +08:00
stdatomic: fix store argument evaluation and signal fence macros
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
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
This commit is contained in:
parent
43c7708b85
commit
e23dabed15
@ -85,7 +85,8 @@ typedef struct {
|
||||
atomic_store_explicit(object, desired, __ATOMIC_RELAXED)
|
||||
|
||||
#define __atomic_store_n(ptr, val, order) \
|
||||
(*(ptr) = (val), __atomic_store((ptr), &(typeof(*(ptr))){val}, (order)))
|
||||
({ __typeof__ ((void)0, *(ptr)) __val = (val); \
|
||||
__atomic_store((ptr), &__val, (order)); })
|
||||
#define atomic_store_explicit(object, desired, order) \
|
||||
({ __typeof__ (object) ptr = (object); \
|
||||
__typeof__ (*ptr) tmp = (desired); \
|
||||
@ -160,7 +161,6 @@ extern void atomic_thread_fence (memory_order);
|
||||
#define __atomic_thread_fence(order) atomic_thread_fence (order)
|
||||
extern void atomic_signal_fence (memory_order);
|
||||
#define __atomic_signal_fence(order) atomic_signal_fence(order)
|
||||
#define atomic_signal_fence(order) __atomic_signal_fence (order)
|
||||
extern bool __atomic_is_lock_free(size_t size, void *ptr);
|
||||
#define atomic_is_lock_free(OBJ) __atomic_is_lock_free (sizeof (*(OBJ)), (OBJ))
|
||||
|
||||
|
||||
45
tests/tests2/151_atomic_header.c
Normal file
45
tests/tests2/151_atomic_header.c
Normal file
@ -0,0 +1,45 @@
|
||||
#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;
|
||||
}
|
||||
5
tests/tests2/151_atomic_header.expect
Normal file
5
tests/tests2/151_atomic_header.expect
Normal file
@ -0,0 +1,5 @@
|
||||
1 1 1 42 8
|
||||
2
|
||||
13
|
||||
42
|
||||
ok
|
||||
Loading…
Reference in New Issue
Block a user