]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: import/mt_list: support building with TCC
authorWilly Tarreau <w@1wt.eu>
Tue, 5 Nov 2024 14:25:31 +0000 (15:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 5 Nov 2024 14:43:17 +0000 (15:43 +0100)
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/import/mt_list.h

index 3f1447ed63e39ee1abb1401076fa7174ee952a5f..85863fa3451eef696158fb18206c7cc6ca2bda11 100644 (file)
 #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))