Skip to content

Commit 033db09

Browse files
committed
BUILD: import/mt_list: support building with TCC
TCC is often convenient to quickly test builds, run CI tests etc. It has limited thread support (e.g. no thread-local stuff) but that is often sufficient for testing. TCC lacks __atomic_exchange_n() but has the exactly equivalent __atomic_exchange(), and doesn't have any barrier. For this reason we force the atomic_exchange to use the stricter SEQ_CST mem ordering that allows to ignore the barrier. [wt: that's upstream commit ca8b865 ("BUILD: support building with TCC")]
1 parent d1adfd9 commit 033db09

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

include/import/mt_list.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333
#include <inttypes.h>
3434
#include <stddef.h>
3535

36+
#if defined(__TINYC__)
37+
/* TCC has __atomic_exchange() for gcc's __atomic_exchange_n(). However it does
38+
* not have any barrier, so we're forcing the order to the stricter SEQ_CST
39+
* instead. There's no thread-local, thus we define __thread, which is only
40+
* used for the PRNG used when sleeping, so we don't care. Anyway tcc with this
41+
* code is mostly used to validate builds and run single-threaded tests.
42+
*/
43+
#include <stdatomic.h>
44+
#define __atomic_exchange_n(val, new, order) __atomic_exchange(val, new, __ATOMIC_SEQ_CST)
45+
#define __atomic_thread_fence(order) do { } while (0)
46+
#define __thread
47+
#endif
48+
3649
/* set NOINLINE to forcefully disable user functions inlining */
3750
#if defined(NOINLINE)
3851
#define MT_INLINE __attribute__((noinline))

0 commit comments

Comments
 (0)