]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compiler: add a new __decl_thread_var() macro to declare local variables
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 17:08:12 +0000 (18:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Mar 2025 17:08:12 +0000 (18:08 +0100)
__decl_thread() already exists but is more suited for struct members.
When using it in a variables block, it appends the final trailing
semi-colon which is a statement that ends the variable block. Better
clean this up and have one precisely for variable blocks. In this
case we can simply define an unused enum value that will consume the
semi-colon. That's what the new macro __decl_thread_var() does.

include/haproxy/compiler.h

index de55fe95bf8cbaa68989ddae0cb39669f6a52a96..c19d2c46afbe14ea0fe73a59f143a90344f960ee 100644 (file)
 #define __decl_thread(decl)
 #endif
 
+/* The __decl_thread_var() statement declares a variable when threads are enabled
+ * or replaces it with an dummy statement to avoid placing a lone semi-colon. The
+ * purpose is to condition the presence of some variables or to the fact that
+ * threads are enabled, without having to enclose them inside an ugly
+ * #ifdef USE_THREAD/#endif clause.
+ */
+#ifdef USE_THREAD
+#define __decl_thread_var(decl) decl
+#else
+#define __decl_thread_var(decl) enum { CONCAT(_dummy_var_decl_,__LINE__), }
+#endif
+
 /* clang has a __has_feature() macro which reports true/false on a number of
  * internally supported features. Let's make sure this macro is always defined
  * and returns zero when not supported.