From 5b9cde4820c31c0019029019d51db3e7c429459c Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 11 Jun 2020 08:33:02 +0200 Subject: [PATCH] REORG: include: move THREAD_LOCAL and __decl_thread() to compiler.h Since these are used as type attributes or conditional clauses, they are used about everywhere and should not require a dependency on thread.h. Moving them to compiler.h along with other similar statements like ALIGN() etc looks more logical; this way they become part of the base API. This allowed to remove thread-t.h from ~12 files, one was found to only require thread-t and not thread and dict.c was found to require thread.h. --- include/haproxy/compiler.h | 20 ++++++++++++++++++++ include/haproxy/dict-t.h | 2 +- include/haproxy/global.h | 1 - include/haproxy/log.h | 1 - include/haproxy/regex-t.h | 1 - include/haproxy/regex.h | 1 - include/haproxy/thread-t.h | 7 ------- include/haproxy/trace.h | 1 - src/dict.c | 1 + src/ev_epoll.c | 1 - src/ev_evports.c | 1 - src/ev_kqueue.c | 1 - src/ev_poll.c | 1 - src/ev_select.c | 1 - src/time.c | 1 - 15 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/haproxy/compiler.h b/include/haproxy/compiler.h index 0e594fa844..ec9d4f393a 100644 --- a/include/haproxy/compiler.h +++ b/include/haproxy/compiler.h @@ -223,4 +223,24 @@ #endif #endif +/* The THREAD_LOCAL type attribute defines thread-local storage and is defined + * to __thread when threads are enabled or empty when disabled. + */ +#ifdef USE_THREAD +#define THREAD_LOCAL __thread +#else +#define THREAD_LOCAL +#endif + +/* The __decl_thread() statement is shows the argument when threads are enabled + * or hides it when disabled. The purpose is to condition the presence of some + * variables or struct members to the fact that threads are enabled, without + * having to enclose them inside a #ifdef USE_THREAD/#endif clause. + */ +#ifdef USE_THREAD +#define __decl_thread(decl) decl +#else +#define __decl_thread(decl) +#endif + #endif /* _HAPROXY_COMPILER_H */ diff --git a/include/haproxy/dict-t.h b/include/haproxy/dict-t.h index b026d305ed..cb2ea9003c 100644 --- a/include/haproxy/dict-t.h +++ b/include/haproxy/dict-t.h @@ -29,7 +29,7 @@ #include #include -#include +#include struct dict_entry { struct ebpt_node value; diff --git a/include/haproxy/global.h b/include/haproxy/global.h index cf8ac1bc55..416784b5b3 100644 --- a/include/haproxy/global.h +++ b/include/haproxy/global.h @@ -24,7 +24,6 @@ #include #include -#include #include #include diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 5346ce467a..4fccb53130 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -29,7 +29,6 @@ #include #include #include -#include extern struct pool_head *pool_head_requri; extern struct pool_head *pool_head_uniqueid; diff --git a/include/haproxy/regex-t.h b/include/haproxy/regex-t.h index 7b7fa03e8c..f265994301 100644 --- a/include/haproxy/regex-t.h +++ b/include/haproxy/regex-t.h @@ -26,7 +26,6 @@ #include #include -#include #ifdef USE_PCRE #include diff --git a/include/haproxy/regex.h b/include/haproxy/regex.h index 6d84ea6138..e093051a6d 100644 --- a/include/haproxy/regex.h +++ b/include/haproxy/regex.h @@ -27,7 +27,6 @@ #include #include -#include extern THREAD_LOCAL regmatch_t pmatch[MAX_MATCH]; diff --git a/include/haproxy/thread-t.h b/include/haproxy/thread-t.h index 20c84ded03..2861d40d43 100644 --- a/include/haproxy/thread-t.h +++ b/include/haproxy/thread-t.h @@ -40,10 +40,7 @@ /********************** THREADS DISABLED ************************/ -#define THREAD_LOCAL /* empty */ - /* These macros allow to make some struct fields or local variables optional */ -#define __decl_thread(decl) #define __decl_spinlock(lock) #define __decl_aligned_spinlock(lock) #define __decl_rwlock(lock) @@ -53,10 +50,6 @@ /********************** THREADS ENABLED ************************/ -#define THREAD_LOCAL __thread - -#define __decl_thread(decl) decl - /* declare a self-initializing spinlock */ #define __decl_spinlock(lock) \ HA_SPINLOCK_T (lock); \ diff --git a/include/haproxy/trace.h b/include/haproxy/trace.h index ae5a3c189b..596b70646d 100644 --- a/include/haproxy/trace.h +++ b/include/haproxy/trace.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include diff --git a/src/dict.c b/src/dict.c index 50fe1eb825..903f073237 100644 --- a/src/dict.c +++ b/src/dict.c @@ -3,6 +3,7 @@ #include #include #include +#include struct dict *new_dict(const char *name) { diff --git a/src/ev_epoll.c b/src/ev_epoll.c index b79db740a0..8096988bd8 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ev_evports.c b/src/ev_evports.c index 81cbe5138f..cbb1bc8fd3 100644 --- a/src/ev_evports.c +++ b/src/ev_evports.c @@ -20,7 +20,6 @@ #include #include -#include #include #include diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c index e1d74d6b22..c699fe23ce 100644 --- a/src/ev_kqueue.c +++ b/src/ev_kqueue.c @@ -19,7 +19,6 @@ #include #include -#include #include #include diff --git a/src/ev_poll.c b/src/ev_poll.c index 8781e6c0d0..53ae81ffe7 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -18,7 +18,6 @@ #include #include -#include #include #include diff --git a/src/ev_select.c b/src/ev_select.c index cee5e8e70f..bf69f35fdf 100644 --- a/src/ev_select.c +++ b/src/ev_select.c @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/src/time.c b/src/time.c index f81ffff57b..9c99fd5309 100644 --- a/src/time.c +++ b/src/time.c @@ -16,7 +16,6 @@ #include #include #include -#include THREAD_LOCAL unsigned int ms_left_scaled; /* milliseconds left for current second (0..2^32-1) */ THREAD_LOCAL unsigned int now_ms; /* internal date in milliseconds (may wrap) */