From: Willy Tarreau Date: Tue, 5 Nov 2024 14:25:31 +0000 (+0100) Subject: BUILD: import/mt_list: support building with TCC X-Git-Tag: v3.1-dev12~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=033db091fc375b62363235c061ba5838e965e606;p=thirdparty%2Fhaproxy.git 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")] --- diff --git a/include/import/mt_list.h b/include/import/mt_list.h index 3f1447ed63..85863fa345 100644 --- a/include/import/mt_list.h +++ b/include/import/mt_list.h @@ -33,6 +33,19 @@ #include #include +#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 +#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))