From ca8b069aa7a015c59b6d6c48180e51b5893f778b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 11 Jun 2020 08:14:01 +0200 Subject: [PATCH] REORG: include: move MAX_THREADS to defaults.h That's already where MAX_PROCS is set, and we already handle the case of the default value so there is no reason for placing it in thread.h given that most call places don't need the rest of the threads definitions. The include was removed from global-t.h and activity.c. --- include/haproxy/defaults.h | 17 +++++++++++++++++ include/haproxy/global-t.h | 1 - include/haproxy/thread-t.h | 9 +-------- src/activity.c | 1 - 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index ef393dcb3..ae4def1ff 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -30,6 +30,23 @@ #define MAX_PROCS LONGBITS #endif +/* MAX_THREADS defines the highest limit for the global nbthread value. It + * defaults to the number of bits in a long integer when threads are enabled + * but may be lowered to save resources on embedded systems. +*/ +#ifndef USE_THREAD +/* threads disabled, 1 thread max */ +#define MAX_THREADS 1 +#define MAX_THREADS_MASK 1 + +#else +/* threads enabled, max_threads defaults to long bits */ +#ifndef MAX_THREADS +#define MAX_THREADS LONGBITS +#endif +#define MAX_THREADS_MASK (~0UL >> (LONGBITS - MAX_THREADS)) +#endif + /* * BUFSIZE defines the size of a read and write buffer. It is the maximum * amount of bytes which can be stored by the proxy for each stream. However, diff --git a/include/haproxy/global-t.h b/include/haproxy/global-t.h index bee8de7a9..9cf30fa7d 100644 --- a/include/haproxy/global-t.h +++ b/include/haproxy/global-t.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include diff --git a/include/haproxy/thread-t.h b/include/haproxy/thread-t.h index d54ec8446..20c84ded0 100644 --- a/include/haproxy/thread-t.h +++ b/include/haproxy/thread-t.h @@ -28,6 +28,7 @@ #endif #include +#include /* Note: this file mainly contains 3 sections: * - one used solely when USE_THREAD is *not* set @@ -40,8 +41,6 @@ /********************** THREADS DISABLED ************************/ #define THREAD_LOCAL /* empty */ -#define MAX_THREADS 1 -#define MAX_THREADS_MASK 1 /* These macros allow to make some struct fields or local variables optional */ #define __decl_thread(decl) @@ -56,12 +55,6 @@ #define THREAD_LOCAL __thread -#ifndef MAX_THREADS -#define MAX_THREADS LONGBITS -#endif - -#define MAX_THREADS_MASK (~0UL >> (LONGBITS - MAX_THREADS)) - #define __decl_thread(decl) decl /* declare a self-initializing spinlock */ diff --git a/src/activity.c b/src/activity.c index 17eb13c1a..5ef38c969 100644 --- a/src/activity.c +++ b/src/activity.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include