1- #include <emscripten/atomic.h>
2- #include <pthread.h>
31#include <assert.h>
2+ #include <pthread.h>
3+ #include <stdatomic.h>
44#include <stdio.h>
55
6- // Test emscripten_atomics_is_lock_free() functions
6+ #include <emscripten/atomic.h>
7+
8+ // Test the various `is_lock_free` functions:
9+ //
10+ // - emscripten_atomics_is_lock_free
11+ // - __atomic_always_lock_free
12+ // - atomic_is_lock_free
713
814void test () {
915 assert (emscripten_atomics_is_lock_free (1 ));
@@ -12,7 +18,30 @@ void test() {
1218 // Chrome is buggy, see
1319 // https://bugs.chromium.org/p/chromium/issues/detail?id=1167449
1420 //assert(emscripten_atomics_is_lock_free(8));
21+ assert (!emscripten_atomics_is_lock_free (16 ));
1522 assert (!emscripten_atomics_is_lock_free (31 ));
23+
24+ // Test compiler buildin __atomic_always_lock_free version
25+ assert (__atomic_always_lock_free (1 , 0 ));
26+ assert (__atomic_always_lock_free (2 , 0 ));
27+ assert (__atomic_always_lock_free (4 , 0 ));
28+ assert (__atomic_always_lock_free (8 , 0 ));
29+ assert (!__atomic_always_lock_free (16 , 0 ));
30+ assert (!__atomic_always_lock_free (31 , 0 ));
31+
32+ // Test C11 atomic_is_lock_free
33+ struct { char a [1 ]; } one ;
34+ struct { char a [2 ]; } two ;
35+ struct { char a [4 ]; } four ;
36+ struct { char a [8 ]; } eight ;
37+ struct { char a [16 ]; } sixteen ;
38+ struct { char a [31 ]; } thirty_one ;
39+ assert (atomic_is_lock_free (& one ));
40+ assert (atomic_is_lock_free (& two ));
41+ assert (atomic_is_lock_free (& four ));
42+ assert (atomic_is_lock_free (& eight ));
43+ assert (!atomic_is_lock_free (& sixteen ));
44+ assert (!atomic_is_lock_free (& thirty_one ));
1645}
1746
1847void * thread_main (void * arg ) {
0 commit comments