MINOR: threads: Use __decl_hathreads to declare locks
This macro should be used to declare variables or struct members depending on
the USE_THREAD compile option. It avoids the encapsulation of such declarations
between #ifdef/#endif. It is used to declare all lock variables.
diff --git a/include/common/buffer.h b/include/common/buffer.h
index acaa79a..4216d93 100644
--- a/include/common/buffer.h
+++ b/include/common/buffer.h
@@ -52,9 +52,7 @@
extern struct buffer buf_empty;
extern struct buffer buf_wanted;
extern struct list buffer_wq;
-#ifdef USE_THREAD
-extern HA_SPINLOCK_T buffer_wq_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T buffer_wq_lock);
int init_buffer();
void deinit_buffer();
diff --git a/include/common/hathreads.h b/include/common/hathreads.h
index 3b8fb0b..31d0f53 100644
--- a/include/common/hathreads.h
+++ b/include/common/hathreads.h
@@ -30,6 +30,8 @@
#ifndef USE_THREAD
+#define __decl_hathreads(decl)
+
#define HA_ATOMIC_CAS(val, old, new) ({((*val) == (*old)) ? (*(val) = (new) , 1) : (*(old) = *(val), 0);})
#define HA_ATOMIC_ADD(val, i) ({*(val) += (i);})
#define HA_ATOMIC_SUB(val, i) ({*(val) -= (i);})
@@ -93,6 +95,8 @@
#include <pthread.h>
#include <import/plock.h>
+#define __decl_hathreads(decl) decl
+
/* TODO: thread: For now, we rely on GCC builtins but it could be a good idea to
* have a header file regrouping all functions dealing with threads. */
#define HA_ATOMIC_CAS(val, old, new) __atomic_compare_exchange_n(val, old, new, 0, 0, 0)
diff --git a/include/common/memory.h b/include/common/memory.h
index ee394f8..a5c0ec4 100644
--- a/include/common/memory.h
+++ b/include/common/memory.h
@@ -47,9 +47,7 @@
struct pool_head {
void **free_list;
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock; /* the spin lock */
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock); /* the spin lock */
struct list list; /* list of all known pools */
unsigned int used; /* how many chunks are currently in use */
unsigned int allocated; /* how many chunks have been allocated */
diff --git a/include/proto/applet.h b/include/proto/applet.h
index 1a621a1..914b496 100644
--- a/include/proto/applet.h
+++ b/include/proto/applet.h
@@ -31,9 +31,7 @@
extern unsigned int nb_applets;
extern unsigned int applets_active_queue;
-#ifdef USE_THREAD
-extern HA_SPINLOCK_T applet_active_lock;
-#endif
+__decl_hathreads(extern HA_SPINLOCK_T applet_active_lock);
extern struct list applet_active_queue;
void applet_run_active();
diff --git a/include/proto/fd.h b/include/proto/fd.h
index 813e4f3..f81c646 100644
--- a/include/proto/fd.h
+++ b/include/proto/fd.h
@@ -39,11 +39,9 @@
extern THREAD_LOCAL int *fd_updt; // FD updates list
extern THREAD_LOCAL int fd_nbupdt; // number of updates in the list
-#ifdef USE_THREAD
-HA_SPINLOCK_T fdtab_lock; /* global lock to protect fdtab array */
-HA_RWLOCK_T fdcache_lock; /* global lock to protect fd_cache array */
-HA_SPINLOCK_T poll_lock; /* global lock to protect poll info */
-#endif
+__decl_hathreads(HA_SPINLOCK_T fdtab_lock); /* global lock to protect fdtab array */
+__decl_hathreads(HA_RWLOCK_T fdcache_lock); /* global lock to protect fd_cache array */
+__decl_hathreads(HA_SPINLOCK_T poll_lock); /* global lock to protect poll info */
/* Deletes an FD from the fdsets, and recomputes the maxfd limit.
* The file descriptor is also closed.
diff --git a/include/proto/signal.h b/include/proto/signal.h
index 084fa7d..32f6ce6 100644
--- a/include/proto/signal.h
+++ b/include/proto/signal.h
@@ -22,9 +22,7 @@
extern struct signal_descriptor signal_state[];
extern struct pool_head *pool2_sig_handlers;
-#ifdef USE_THREAD
-extern HA_SPINLOCK_T signals_lock;
-#endif
+__decl_hathreads(extern HA_SPINLOCK_T signals_lock);
void signal_handler(int sig);
void __signal_process_queue();
diff --git a/include/proto/task.h b/include/proto/task.h
index e6ba461..9461b59 100644
--- a/include/proto/task.h
+++ b/include/proto/task.h
@@ -89,10 +89,9 @@
extern unsigned int niced_tasks; /* number of niced tasks in the run queue */
extern struct pool_head *pool2_task;
extern struct pool_head *pool2_notification;
-#ifdef USE_THREAD
-extern HA_SPINLOCK_T rq_lock; /* spin lock related to run queue */
-extern HA_SPINLOCK_T wq_lock; /* spin lock related to wait queue */
-#endif
+
+__decl_hathreads(extern HA_SPINLOCK_T rq_lock); /* spin lock related to run queue */
+__decl_hathreads(extern HA_SPINLOCK_T wq_lock); /* spin lock related to wait queue */
/* return 0 if task is in run queue, otherwise non-zero */
static inline int task_in_rq(struct task *t)
diff --git a/include/types/backend.h b/include/types/backend.h
index 68d3125..c7f9fa3 100644
--- a/include/types/backend.h
+++ b/include/types/backend.h
@@ -147,9 +147,8 @@
struct lb_fwlc fwlc;
struct lb_chash chash;
struct lb_fas fas;
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
+
/* Call backs for some actions. Any of them may be NULL (thus should be ignored). */
void (*update_server_eweight)(struct server *); /* to be called after eweight change */
void (*set_server_status_up)(struct server *); /* to be called after status changes to UP */
diff --git a/include/types/dns.h b/include/types/dns.h
index bdc8cfc..b1f068a 100644
--- a/include/types/dns.h
+++ b/include/types/dns.h
@@ -193,9 +193,7 @@
struct eb_root query_ids; /* tree to quickly lookup/retrieve query ids currently in use
* used by each nameserver, but stored in resolvers since there must
* be a unique relation between an eb_root and an eb_node (resolution) */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
struct list list; /* resolvers list */
};
diff --git a/include/types/fd.h b/include/types/fd.h
index 2da6599..2d8237b 100644
--- a/include/types/fd.h
+++ b/include/types/fd.h
@@ -95,9 +95,7 @@
void (*iocb)(int fd); /* I/O handler */
void *owner; /* the connection or listener associated with this fd, NULL if closed */
unsigned long thread_mask; /* mask of thread IDs authorized to process the task */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
unsigned int cache; /* position+1 in the FD cache. 0=not in cache. */
unsigned char state; /* FD state for read and write directions (2*3 bits) */
unsigned char ev; /* event seen in return of poll() : FD_POLL_* */
diff --git a/include/types/global.h b/include/types/global.h
index 48b6f9d..6793c83 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -163,11 +163,7 @@
} unix_bind;
#ifdef USE_CPU_AFFINITY
unsigned long cpu_map[LONGBITS]; /* list of CPU masks for the 32/64 first processes */
-
-#ifdef USE_THREAD
- unsigned long thread_map[LONGBITS][LONGBITS]; /* list of CPU masks for the 32/64 first threads per process */
-#endif
-
+ __decl_hathreads(unsigned long thread_map[LONGBITS][LONGBITS]); /* list of CPU masks for the 32/64 first threads per process */
#endif
struct proxy *stats_fe; /* the frontend holding the stats settings */
struct vars vars; /* list of variables for the process scope. */
diff --git a/include/types/listener.h b/include/types/listener.h
index ac39758..545f88c 100644
--- a/include/types/listener.h
+++ b/include/types/listener.h
@@ -200,9 +200,7 @@
int tcp_ut; /* for TCP, user timeout */
char *interface; /* interface name or NULL */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
const struct netns_entry *netns; /* network namespace of the listener*/
diff --git a/include/types/pattern.h b/include/types/pattern.h
index d5c340a..a0bb08e 100644
--- a/include/types/pattern.h
+++ b/include/types/pattern.h
@@ -107,9 +107,7 @@
char *display; /* String displayed to identify the pattern origin. */
struct list head; /* The head of the list of struct pat_ref_elt. */
struct list pat; /* The head of the list of struct pattern_expr. */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock; /* Lock used to protect pat ref elements */
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock); /* Lock used to protect pat ref elements */
};
/* This is a part of struct pat_ref. Each entry contain one
@@ -202,9 +200,7 @@
struct eb_root pattern_tree; /* may be used for lookup in large datasets */
struct eb_root pattern_tree_2; /* may be used for different types */
int mflags; /* flags relative to the parsing or matching method. */
-#ifdef USE_THREAD
- HA_RWLOCK_T lock; /* lock used to protect patterns */
-#endif
+ __decl_hathreads(HA_RWLOCK_T lock); /* lock used to protect patterns */
};
/* This is a list of expression. A struct pattern_expr can be used by
diff --git a/include/types/peers.h b/include/types/peers.h
index 2fc7435..58c8c4e 100644
--- a/include/types/peers.h
+++ b/include/types/peers.h
@@ -67,9 +67,7 @@
struct shared_table *remote_table;
struct shared_table *last_local_table;
struct shared_table *tables;
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock; /* lock used to handle this peer section */
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock); /* lock used to handle this peer section */
struct peer *next; /* next peer in the list */
};
diff --git a/include/types/proxy.h b/include/types/proxy.h
index 719c8dd..3b7d9a3 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -239,9 +239,7 @@
* code even though they are not checks. This structure
* is as a parameter to the check code.
* Each check corresponds to a mailer */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
};
struct proxy {
@@ -444,10 +442,7 @@
* name is used
*/
struct list filter_configs; /* list of the filters that are declared on this proxy */
-
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
};
struct switching_rule {
diff --git a/include/types/server.h b/include/types/server.h
index 76225f7..adedca4 100644
--- a/include/types/server.h
+++ b/include/types/server.h
@@ -286,10 +286,7 @@
struct sample_expr *sni; /* sample expression for SNI */
} ssl_ctx;
#endif
-
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
struct {
const char *file; /* file where the section appears */
int line; /* line where the section appears */
diff --git a/include/types/spoe.h b/include/types/spoe.h
index aead2ba..53e7200 100644
--- a/include/types/spoe.h
+++ b/include/types/spoe.h
@@ -264,10 +264,7 @@
struct list applets; /* List of available SPOE applets */
struct list sending_queue; /* Queue of streams waiting to send data */
struct list waiting_queue; /* Queue of streams waiting for a ack, in async mode */
-
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
} *rt;
};
diff --git a/include/types/stick_table.h b/include/types/stick_table.h
index 4f5de99..4a8d8c7 100644
--- a/include/types/stick_table.h
+++ b/include/types/stick_table.h
@@ -129,9 +129,7 @@
struct stksess {
unsigned int expire; /* session expiration date */
unsigned int ref_cnt; /* reference count, can only purge when zero */
-#ifdef USE_THREAD
- HA_RWLOCK_T lock; /* lock related to the table entry */
-#endif
+ __decl_hathreads(HA_RWLOCK_T lock); /* lock related to the table entry */
struct eb32_node exp; /* ebtree node used to hold the session in expiration tree */
struct eb32_node upd; /* ebtree node used to hold the update sequence tree */
struct ebmb_node key; /* ebtree node used to hold the session in table */
@@ -146,9 +144,7 @@
struct eb_root exps; /* head of sticky session expiration tree */
struct eb_root updates; /* head of sticky updates sequence tree */
struct pool_head *pool; /* pool used to allocate sticky sessions */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock; /* spin lock related to the table */
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock); /* spin lock related to the table */
struct task *exp_task; /* expiration task */
struct task *sync_task; /* sync task */
unsigned int update;
diff --git a/include/types/task.h b/include/types/task.h
index 70fc681..991e3a4 100644
--- a/include/types/task.h
+++ b/include/types/task.h
@@ -57,9 +57,7 @@
struct list wake_me; /* Part of list of signals to be targeted if an
event occurs. */
struct task *task; /* The task to be wake if an event occurs. */
-#ifdef USE_THREAD
- HA_SPINLOCK_T lock;
-#endif
+ __decl_hathreads(HA_SPINLOCK_T lock);
};
/* The base for all tasks */
diff --git a/include/types/vars.h b/include/types/vars.h
index 8a4f7aa..9b166e9 100644
--- a/include/types/vars.h
+++ b/include/types/vars.h
@@ -18,9 +18,7 @@
struct list head;
enum vars_scope scope;
unsigned int size;
-#ifdef USE_THREAD
- HA_RWLOCK_T rwlock;
-#endif
+ __decl_hathreads(HA_RWLOCK_T rwlock);
};
/* This struct describes a variable. */
diff --git a/src/applet.c b/src/applet.c
index 0e550c2..1df6b09 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -22,10 +22,7 @@
unsigned int nb_applets = 0;
unsigned int applets_active_queue = 0;
-
-#ifdef USE_THREAD
-HA_SPINLOCK_T applet_active_lock; /* spin lock related to applet active queue */
-#endif
+__decl_hathreads(HA_SPINLOCK_T applet_active_lock); /* spin lock related to applet active queue */
struct list applet_active_queue = LIST_HEAD_INIT(applet_active_queue);
diff --git a/src/buffer.c b/src/buffer.c
index b365888..66d117a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -33,9 +33,7 @@
/* list of objects waiting for at least one buffer */
struct list buffer_wq = LIST_HEAD_INIT(buffer_wq);
-#ifdef USE_THREAD
-HA_SPINLOCK_T buffer_wq_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T buffer_wq_lock);
/* this buffer is always the same size as standard buffers and is used for
* swapping data inside a buffer.
diff --git a/src/checks.c b/src/checks.c
index 8d5822a..4b47cf3 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -1613,9 +1613,7 @@
static struct list pid_list = LIST_HEAD_INIT(pid_list);
static struct pool_head *pool2_pid_list;
-#ifdef USE_THREAD
-HA_SPINLOCK_T pid_list_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T pid_list_lock);
void block_sigchld(void)
{
diff --git a/src/compression.c b/src/compression.c
index 594399a..4961ef3 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -42,9 +42,7 @@
#if defined(USE_SLZ) || defined(USE_ZLIB)
-#ifdef USE_THREAD
-static HA_SPINLOCK_T comp_pool_lock;
-#endif
+__decl_hathreads(static HA_SPINLOCK_T comp_pool_lock);
#endif
#ifdef USE_ZLIB
diff --git a/src/fd.c b/src/fd.c
index d2e9569..9fb09ab 100644
--- a/src/fd.c
+++ b/src/fd.c
@@ -174,11 +174,9 @@
THREAD_LOCAL int *fd_updt = NULL; // FD updates list
THREAD_LOCAL int fd_nbupdt = 0; // number of updates in the list
-#ifdef USE_THREAD
-HA_SPINLOCK_T fdtab_lock; /* global lock to protect fdtab array */
-HA_RWLOCK_T fdcache_lock; /* global lock to protect fd_cache array */
-HA_SPINLOCK_T poll_lock; /* global lock to protect poll info */
-#endif
+__decl_hathreads(HA_SPINLOCK_T fdtab_lock); /* global lock to protect fdtab array */
+__decl_hathreads(HA_RWLOCK_T fdcache_lock); /* global lock to protect fd_cache array */
+__decl_hathreads(HA_SPINLOCK_T poll_lock); /* global lock to protect poll info */
/* Deletes an FD from the fdsets, and recomputes the maxfd limit.
* The file descriptor is also closed.
diff --git a/src/hlua.c b/src/hlua.c
index 439bbf4..dbdc975 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -115,9 +115,7 @@
* and RESET_SAFE_LJMP manipulates the Lua stack, so it will be careful
* to set mutex around these functions.
*/
-#ifdef USE_THREAD
-HA_SPINLOCK_T hlua_global_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T hlua_global_lock);
THREAD_LOCAL jmp_buf safe_ljmp_env;
static int hlua_panic_safe(lua_State *L) { return 0; }
static int hlua_panic_ljmp(lua_State *L) { longjmp(safe_ljmp_env, 1); }
diff --git a/src/listener.c b/src/listener.c
index a6bd449..c7db79a 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -38,10 +38,8 @@
#include <proto/stream.h>
#include <proto/task.h>
-#ifdef USE_THREAD
/* listner_queue lock (same for global and per proxy queues) */
-static HA_SPINLOCK_T lq_lock;
-#endif
+__decl_hathreads(static HA_SPINLOCK_T lq_lock);
/* List head of all known bind keywords */
static struct bind_kw_list bind_keywords = {
diff --git a/src/pattern.c b/src/pattern.c
index 47e8aee..fe672f1 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -155,9 +155,7 @@
struct list pattern_reference = LIST_HEAD_INIT(pattern_reference);
static struct lru64_head *pat_lru_tree;
-#ifdef USE_THREAD
-HA_SPINLOCK_T pat_lru_tree_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T pat_lru_tree_lock);
static unsigned long long pat_lru_seed;
/*
diff --git a/src/pipe.c b/src/pipe.c
index c161f96..bab8620 100644
--- a/src/pipe.c
+++ b/src/pipe.c
@@ -22,9 +22,9 @@
struct pool_head *pool2_pipe = NULL;
struct pipe *pipes_live = NULL; /* pipes which are still ready to use */
-#ifdef USE_THREAD
-HA_SPINLOCK_T pipes_lock; /* lock used to protect pipes list */
-#endif
+
+__decl_hathreads(HA_SPINLOCK_T pipes_lock); /* lock used to protect pipes list */
+
int pipes_used = 0; /* # of pipes in use (2 fds each) */
int pipes_free = 0; /* # of pipes unused */
diff --git a/src/server.c b/src/server.c
index d79e951..5e995f8 100644
--- a/src/server.c
+++ b/src/server.c
@@ -45,10 +45,7 @@
#include <netinet/tcp.h>
struct list updated_servers = LIST_HEAD_INIT(updated_servers);
-
-#ifdef USE_THREAD
-HA_SPINLOCK_T updated_servers_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T updated_servers_lock);
static void srv_register_update(struct server *srv);
static void srv_update_state(struct server *srv, int version, char **params);
diff --git a/src/signal.c b/src/signal.c
index 3409e76..e996c46 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -31,9 +31,7 @@
sigset_t blocked_sig;
int signal_pending = 0; /* non-zero if t least one signal remains unprocessed */
-#ifdef USE_THREAD
-HA_SPINLOCK_T signals_lock;
-#endif
+__decl_hathreads(HA_SPINLOCK_T signals_lock);
/* Common signal handler, used by all signals. Received signals are queued.
* Signal number zero has a specific status, as it cannot be delivered by the
diff --git a/src/ssl_sock.c b/src/ssl_sock.c
index 72d9b8a..25f3eca 100644
--- a/src/ssl_sock.c
+++ b/src/ssl_sock.c
@@ -206,6 +206,7 @@
};
#ifdef USE_THREAD
+
static HA_RWLOCK_T *ssl_rwlocks;
@@ -246,6 +247,7 @@
return 0;
}
+
#endif
@@ -302,10 +304,7 @@
static struct lru64_head *ssl_ctx_lru_tree = NULL;
static unsigned int ssl_ctx_lru_seed = 0;
static unsigned int ssl_ctx_serial;
-
-#ifdef USE_THREAD
-static HA_RWLOCK_T ssl_ctx_lru_rwlock;
-#endif
+__decl_hathreads(static HA_RWLOCK_T ssl_ctx_lru_rwlock);
#endif // SSL_CTRL_SET_TLSEXT_HOSTNAME
diff --git a/src/stream.c b/src/stream.c
index 19d94f3..d71b6ce 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -62,10 +62,8 @@
struct pool_head *pool2_stream;
struct list streams;
+__decl_hathreads(HA_SPINLOCK_T streams_lock);
-#ifdef USE_THREAD
-HA_SPINLOCK_T streams_lock;
-#endif
/* List of all use-service keywords. */
static struct list service_keywords = LIST_HEAD_INIT(service_keywords);
diff --git a/src/task.c b/src/task.c
index 9882903..4f9b049 100644
--- a/src/task.c
+++ b/src/task.c
@@ -37,10 +37,8 @@
unsigned int nb_tasks_cur = 0; /* copy of the tasks count */
unsigned int niced_tasks = 0; /* number of niced tasks in the run queue */
-#ifdef USE_THREAD
-HA_SPINLOCK_T rq_lock; /* spin lock related to run queue */
-HA_SPINLOCK_T wq_lock; /* spin lock related to wait queue */
-#endif
+__decl_hathreads(HA_SPINLOCK_T rq_lock); /* spin lock related to run queue */
+__decl_hathreads(HA_SPINLOCK_T wq_lock); /* spin lock related to wait queue */
static struct eb_root timers; /* sorted timers tree */
static struct eb_root rqueue; /* tree constituting the run queue */
diff --git a/src/vars.c b/src/vars.c
index fef3685..2192fa5 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -32,9 +32,7 @@
static unsigned int var_reqres_limit = 0;
-#ifdef USE_THREAD
-HA_RWLOCK_T var_names_rwlock;
-#endif
+__decl_hathreads(HA_RWLOCK_T var_names_rwlock);
/* This function adds or remove memory size from the accounting. The inner
* pointers may be null when setting the outer ones only.