| 1 |
/* Test atomic_is_lock_free. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-std=c11 -pedantic-errors" } */ |
| 4 |
|
| 5 |
#include <stdatomic.h> |
| 6 |
#include <stdint.h> |
| 7 |
|
| 8 |
extern void abort (void); |
| 9 |
|
| 10 |
_Atomic _Bool aba; |
| 11 |
atomic_bool abt; |
| 12 |
_Atomic char aca; |
| 13 |
atomic_char act; |
| 14 |
_Atomic __CHAR16_TYPE__ ac16a; |
| 15 |
atomic_char16_t ac16t; |
| 16 |
_Atomic __CHAR32_TYPE__ ac32a; |
| 17 |
atomic_char32_t ac32t; |
| 18 |
_Atomic __WCHAR_TYPE__ awca; |
| 19 |
atomic_wchar_t awct; |
| 20 |
_Atomic short asa; |
| 21 |
atomic_short ast; |
| 22 |
_Atomic int aia; |
| 23 |
atomic_int ait; |
| 24 |
_Atomic long ala; |
| 25 |
atomic_long alt; |
| 26 |
_Atomic long long alla; |
| 27 |
atomic_llong allt; |
| 28 |
void *_Atomic apa; |
| 29 |
|
| 30 |
#define CHECK_TYPE(MACRO, V1, V2) \ |
| 31 |
do \ |
| 32 |
{ \ |
| 33 |
int r1 = MACRO; \ |
| 34 |
int r2 = atomic_is_lock_free (&V1); \ |
| 35 |
int r3 = atomic_is_lock_free (&V2); \ |
| 36 |
if (r1 != 0 && r1 != 1 && r1 != 2) \ |
| 37 |
abort (); \ |
| 38 |
if (r2 != 0 && r2 != 1) \ |
| 39 |
abort (); \ |
| 40 |
if (r3 != 0 && r3 != 1) \ |
| 41 |
abort (); \ |
| 42 |
if (r1 == 2 && r2 != 1) \ |
| 43 |
abort (); \ |
| 44 |
if (r1 == 2 && r3 != 1) \ |
| 45 |
abort (); \ |
| 46 |
if (r1 == 0 && r2 != 0) \ |
| 47 |
abort (); \ |
| 48 |
if (r1 == 0 && r3 != 0) \ |
| 49 |
abort (); \ |
| 50 |
} \ |
| 51 |
while (0) |
| 52 |
|
| 53 |
int |
| 54 |
main () |
| 55 |
{ |
| 56 |
CHECK_TYPE (ATOMIC_BOOL_LOCK_FREE, aba, abt); |
| 57 |
CHECK_TYPE (ATOMIC_CHAR_LOCK_FREE, aca, act); |
| 58 |
CHECK_TYPE (ATOMIC_CHAR16_T_LOCK_FREE, ac16a, ac16t); |
| 59 |
CHECK_TYPE (ATOMIC_CHAR32_T_LOCK_FREE, ac32a, ac32t); |
| 60 |
CHECK_TYPE (ATOMIC_WCHAR_T_LOCK_FREE, awca, awct); |
| 61 |
CHECK_TYPE (ATOMIC_SHORT_LOCK_FREE, asa, ast); |
| 62 |
CHECK_TYPE (ATOMIC_INT_LOCK_FREE, aia, ait); |
| 63 |
CHECK_TYPE (ATOMIC_LONG_LOCK_FREE, ala, alt); |
| 64 |
CHECK_TYPE (ATOMIC_LLONG_LOCK_FREE, alla, allt); |
| 65 |
CHECK_TYPE (ATOMIC_POINTER_LOCK_FREE, apa, apa); |
| 66 |
|
| 67 |
return 0; |
| 68 |
} |