]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: init: use self-initializing spinlocks and rwlocks
authorWilly Tarreau <w@1wt.eu>
Sun, 25 Nov 2018 19:12:18 +0000 (20:12 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 26 Nov 2018 18:50:32 +0000 (19:50 +0100)
This patch replaces a number of __decl_hathread() followed by HA_SPIN_INIT
or HA_RWLOCK_INIT by the new __decl_spinlock() or __decl_rwlock() which
automatically registers the lock for initialization in during the STG_LOCK
init stage. A few static modifiers were lost in the process, but since they
were not essential at all it was not worth extending the API to provide such
a variant.

src/buffer.c
src/checks.c
src/compression.c
src/hlua.c
src/listener.c
src/pattern.c
src/pipe.c
src/ssl_sock.c
src/stream.c
src/task.c
src/vars.c

index d6bd242d489dbe79b708af97506605f8e037aa47..e55c5bdd2a4b23a21915f6de79742213af7d801a 100644 (file)
@@ -24,7 +24,7 @@ struct pool_head *pool_head_buffer;
 
 /* list of objects waiting for at least one buffer */
 struct list buffer_wq = LIST_HEAD_INIT(buffer_wq);
-__decl_hathreads(HA_SPINLOCK_T __attribute__((aligned(64))) buffer_wq_lock);
+__decl_aligned_spinlock(buffer_wq_lock);
 
 /* perform minimal intializations, report 0 in case of error, 1 if OK. */
 int init_buffer()
@@ -46,8 +46,6 @@ int init_buffer()
        if (global.tune.buf_limit)
                pool_head_buffer->limit = global.tune.buf_limit;
 
-       HA_SPIN_INIT(&buffer_wq_lock);
-
        buffer = pool_refill_alloc(pool_head_buffer, pool_head_buffer->minavail - 1);
        if (!buffer)
                return 0;
index 4829a54462677ee6960d5f8648090da801252151..53950932d27b4ae595252e83b511aafbdf6f92df 100644 (file)
@@ -1632,7 +1632,7 @@ static int connect_conn_chk(struct task *t)
 
 static struct list pid_list = LIST_HEAD_INIT(pid_list);
 static struct pool_head *pool_head_pid_list;
-__decl_hathreads(HA_SPINLOCK_T pid_list_lock);
+__decl_spinlock(pid_list_lock);
 
 void block_sigchld(void)
 {
@@ -1736,8 +1736,6 @@ static int init_pid_list(void)
                return 1;
        }
 
-       HA_SPIN_INIT(&pid_list_lock);
-
        return 0;
 }
 
index b725e3130589645a51ea86c4d3e201126d8a8ca8..af44f4d6d11353ded8eac36d16bd91d352cec19b 100644 (file)
@@ -42,7 +42,7 @@
 
 
 #if defined(USE_ZLIB)
-__decl_hathreads(static HA_SPINLOCK_T comp_pool_lock);
+__decl_spinlock(comp_pool_lock);
 #endif
 
 #ifdef USE_ZLIB
@@ -721,7 +721,6 @@ static void __comp_fetch_init(void)
        global.maxzlibmem = DEFAULT_MAXZLIBMEM * 1024U * 1024U;
 #endif
 #ifdef USE_ZLIB
-       HA_SPIN_INIT(&comp_pool_lock);
        memprintf(&ptr, "Built with zlib version : " ZLIB_VERSION);
        memprintf(&ptr, "%s\nRunning on zlib version : %s", ptr, zlibVersion());
 #elif defined(USE_SLZ)
index d34aa798d8ec610673bf415d3f28215d13d0832b..820ddf58afaec026e7aaa06f8585ccb7410d29d6 100644 (file)
  * and RESET_SAFE_LJMP manipulates the Lua stack, so it will be careful
  * to set mutex around these functions.
  */
-__decl_hathreads(HA_SPINLOCK_T hlua_global_lock);
+__decl_spinlock(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); }
@@ -7670,8 +7670,6 @@ void hlua_init(void)
        };
 #endif
 
-       HA_SPIN_INIT(&hlua_global_lock);
-
        /* Initialise struct hlua and com signals pool */
        pool_head_hlua = create_pool("hlua", sizeof(struct hlua), MEM_F_SHARED);
 
index 2a38cfd2bd16f9eecb64ebcc1646d7eeac2cca15..4bcf2d8ac7b10d73d2f27b49e03b673be598649c 100644 (file)
@@ -43,7 +43,7 @@
 #include <proto/task.h>
 
  /* listner_queue lock (same for global and per proxy queues) */
-__decl_hathreads(static HA_SPINLOCK_T lq_lock);
+__decl_spinlock(lq_lock);
 
 /* List head of all known bind keywords */
 static struct bind_kw_list bind_keywords = {
@@ -1047,12 +1047,6 @@ static struct bind_kw_list bind_kws = { "ALL", { }, {
 
 INITCALL1(STG_REGISTER, bind_register_keywords, &bind_kws);
 
-__attribute__((constructor))
-static void __listener_init(void)
-{
-       HA_SPIN_INIT(&lq_lock);
-}
-
 /*
  * Local variables:
  *  c-indent-level: 8
index 6b00385f08a6bf25f071180cdc38662fea4f09e4..93cdede116e6b4ad62a52ca4fd8b47718dc416e5 100644 (file)
@@ -155,7 +155,7 @@ static THREAD_LOCAL struct sample_data static_sample_data;
 struct list pattern_reference = LIST_HEAD_INIT(pattern_reference);
 
 static struct lru64_head *pat_lru_tree;
-__decl_hathreads(HA_SPINLOCK_T pat_lru_tree_lock);
+__decl_spinlock(pat_lru_tree_lock);
 static unsigned long long pat_lru_seed;
 
 /*
@@ -2696,7 +2696,6 @@ void pattern_finalize_config(void)
        pat_lru_seed = random();
        if (global.tune.pattern_cache) {
                pat_lru_tree = lru64_new(global.tune.pattern_cache);
-               HA_SPIN_INIT(&pat_lru_tree_lock);
        }
 
        list_for_each_entry(ref, &pattern_reference, list) {
index a3d7ccd18a7da5303c9a3e1fd2b009abd8604e44..a82283a930acd9b780391a17c7ff20f4da830e92 100644 (file)
@@ -23,7 +23,7 @@
 struct pool_head *pool_head_pipe = NULL;
 struct pipe *pipes_live = NULL; /* pipes which are still ready to use */
 
-__decl_hathreads(HA_SPINLOCK_T pipes_lock); /* lock used to protect pipes list */
+__decl_spinlock(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 */
@@ -32,9 +32,6 @@ int pipes_free = 0;             /* # of pipes unused */
 static void init_pipe()
 {
        pool_head_pipe = create_pool("pipe", sizeof(struct pipe), MEM_F_SHARED);
-       pipes_used = 0;
-       pipes_free = 0;
-       HA_SPIN_INIT(&pipes_lock);
 }
 
 /* return a pre-allocated empty pipe. Try to allocate one if there isn't any
index 174ed1f955679f7509247fae1d015098c642a757..3be4b2aedc09adf5527f53f005c2920fa6adab7b 100644 (file)
@@ -322,7 +322,7 @@ static char *x509v3_ext_values[X509V3_EXT_SIZE] = {
 static struct lru64_head *ssl_ctx_lru_tree = NULL;
 static unsigned int       ssl_ctx_lru_seed = 0;
 static unsigned int      ssl_ctx_serial;
-__decl_hathreads(static HA_RWLOCK_T ssl_ctx_lru_rwlock);
+__decl_rwlock(ssl_ctx_lru_rwlock);
 
 #endif // SSL_CTRL_SET_TLSEXT_HOSTNAME
 
@@ -4929,7 +4929,6 @@ ssl_sock_load_ca(struct bind_conf *bind_conf)
 #if (defined SSL_CTRL_SET_TLSEXT_HOSTNAME && !defined SSL_NO_GENERATE_CERTIFICATES)
        if (global_ssl.ctx_cache) {
                ssl_ctx_lru_tree = lru64_new(global_ssl.ctx_cache);
-               HA_RWLOCK_INIT(&ssl_ctx_lru_rwlock);
        }
        ssl_ctx_lru_seed = (unsigned int)time(NULL);
        ssl_ctx_serial   = now_ms;
index 31146d27fad47d421c8958e4eed8497b05aff0e1..6b097c3257dec4da4071cf2c8e9e74a5017ec84d 100644 (file)
@@ -65,7 +65,7 @@
 
 struct pool_head *pool_head_stream;
 struct list streams;
-__decl_hathreads(HA_SPINLOCK_T streams_lock);
+__decl_spinlock(streams_lock);
 
 /* List of all use-service keywords. */
 static struct list service_keywords = LIST_HEAD_INIT(service_keywords);
@@ -515,7 +515,6 @@ void stream_release_buffers(struct stream *s)
 int init_stream()
 {
        LIST_INIT(&streams);
-       HA_SPIN_INIT(&streams_lock);
        pool_head_stream = create_pool("stream", sizeof(struct stream), MEM_F_SHARED);
        return pool_head_stream != NULL;
 }
index 5c5e1043884ccfb9645fb75e180765c36263aab9..ef1db82b6286caf322ba1a6490b782e0d903a16d 100644 (file)
@@ -44,8 +44,8 @@ unsigned int niced_tasks = 0;      /* number of niced tasks in the run queue */
 THREAD_LOCAL struct task *curr_task = NULL; /* task currently running or NULL */
 THREAD_LOCAL struct eb32sc_node *rq_next = NULL; /* Next task to be potentially run */
 
-__decl_hathreads(HA_SPINLOCK_T __attribute__((aligned(64))) rq_lock); /* spin lock related to run queue */
-__decl_hathreads(HA_SPINLOCK_T __attribute__((aligned(64))) wq_lock); /* spin lock related to wait queue */
+__decl_aligned_spinlock(rq_lock); /* spin lock related to run queue */
+__decl_aligned_spinlock(wq_lock); /* spin lock related to wait queue */
 
 #ifdef USE_THREAD
 struct eb_root timers;      /* sorted timers tree, global */
@@ -478,8 +478,6 @@ int init_task()
        memset(&timers, 0, sizeof(timers));
        memset(&rqueue, 0, sizeof(rqueue));
 #endif
-       HA_SPIN_INIT(&wq_lock);
-       HA_SPIN_INIT(&rq_lock);
        memset(&task_per_thread, 0, sizeof(task_per_thread));
        for (i = 0; i < MAX_THREADS; i++) {
                LIST_INIT(&task_per_thread[i].task_list);
index e44a78600a51527bbbd5df04e6ae9ed60febdc7c..2bc46b164366e58d68998957cdb656574afe0a86 100644 (file)
@@ -34,8 +34,7 @@ static unsigned int var_sess_limit = 0;
 static unsigned int var_txn_limit = 0;
 static unsigned int var_reqres_limit = 0;
 
-
-__decl_hathreads(HA_RWLOCK_T var_names_rwlock);
+__decl_rwlock(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.
@@ -927,6 +926,4 @@ __attribute__((constructor))
 static void __vars_init(void)
 {
        var_pool = create_pool("vars", sizeof(struct var), MEM_F_SHARED);
-
-       HA_RWLOCK_INIT(&var_names_rwlock);
 }