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")]
#include <inttypes.h>
#include <stddef.h>
+#if defined(__TINYC__)
+/* TCC has __atomic_exchange() for gcc's __atomic_exchange_n(). However it does
+ * not have any barrier, so we're forcing the order to the stricter SEQ_CST
+ * instead. There's no thread-local, thus we define __thread, which is only
+ * used for the PRNG used when sleeping, so we don't care. Anyway tcc with this
+ * code is mostly used to validate builds and run single-threaded tests.
+ */
+#include <stdatomic.h>
+#define __atomic_exchange_n(val, new, order) __atomic_exchange(val, new, __ATOMIC_SEQ_CST)
+#define __atomic_thread_fence(order) do { } while (0)
+#define __thread
+#endif
+
/* set NOINLINE to forcefully disable user functions inlining */
#if defined(NOINLINE)
#define MT_INLINE __attribute__((noinline))