| 12 | // - atomic_is_lock_free |
| 13 | |
| 14 | void test() { |
| 15 | assert(emscripten_atomics_is_lock_free(1)); |
| 16 | assert(emscripten_atomics_is_lock_free(2)); |
| 17 | assert(emscripten_atomics_is_lock_free(4)); |
| 18 | assert(emscripten_atomics_is_lock_free(8)); |
| 19 | assert(!emscripten_atomics_is_lock_free(16)); |
| 20 | assert(!emscripten_atomics_is_lock_free(31)); |
| 21 | |
| 22 | // Test compiler buildin __atomic_always_lock_free version |
| 23 | assert(__atomic_always_lock_free(1, 0)); |
| 24 | assert(__atomic_always_lock_free(2, 0)); |
| 25 | assert(__atomic_always_lock_free(4, 0)); |
| 26 | assert(__atomic_always_lock_free(8, 0)); |
| 27 | assert(!__atomic_always_lock_free(16, 0)); |
| 28 | assert(!__atomic_always_lock_free(31, 0)); |
| 29 | |
| 30 | // Test C11 atomic_is_lock_free |
| 31 | struct { char a[1]; } one; |
| 32 | struct { char a[2]; } two; |
| 33 | struct { char a[4]; } four; |
| 34 | struct { char a[8]; } eight; |
| 35 | struct { char a[16]; } sixteen; |
| 36 | struct { char a[31]; } thirty_one; |
| 37 | assert(atomic_is_lock_free(&one)); |
| 38 | assert(atomic_is_lock_free(&two)); |
| 39 | assert(atomic_is_lock_free(&four)); |
| 40 | assert(atomic_is_lock_free(&eight)); |
| 41 | assert(!atomic_is_lock_free(&sixteen)); |
| 42 | assert(!atomic_is_lock_free(&thirty_one)); |
| 43 | } |
| 44 | |
| 45 | void* thread_main(void* arg) { |
| 46 | test(); |
no test coverage detected