From b4f7cc3839dfe826cbcf937d54ea2e6dcd9ba621 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 3 May 2019 09:27:30 +0200 Subject: [PATCH] MINOR: init/threads: remove the useless tids[] array It's still obscure how we managed to initialize an array of integers with values always equal to the index, just to retrieve the value from an opaque pointer to the index instead of directly using it! I suspect it's a leftover from the very early threading experiments. This commit gets rid of this and simply passes the thread ID as the argument to run_thread_poll_loop(), thus significantly simplifying the few call places and removing the need to allocate then free an array of identity. --- src/haproxy.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/haproxy.c b/src/haproxy.c index 1aeae9984..43b2118e9 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -690,7 +690,7 @@ static void mworker_loop() leave */ fork_poller(); - run_thread_poll_loop((int []){0}); + run_thread_poll_loop(0); } /* @@ -2492,7 +2492,7 @@ static void *run_thread_poll_loop(void *data) struct per_thread_deinit_fct *ptdf; __decl_hathreads(static HA_SPINLOCK_T start_lock); - ha_set_tid(*((unsigned int *)data)); + ha_set_tid((unsigned long)data); tv_update_date(-1,-1); list_for_each_entry(ptif, &per_thread_init_list, list) { @@ -3125,15 +3125,10 @@ int main(int argc, char **argv) */ #ifdef USE_THREAD { - unsigned int *tids = calloc(global.nbthread, sizeof(unsigned int)); pthread_t *threads = calloc(global.nbthread, sizeof(pthread_t)); int i; sigset_t blocked_sig, old_sig; - /* Init tids array */ - for (i = 0; i < global.nbthread; i++) - tids[i] = i; - /* ensure the signals will be blocked in every thread */ sigfillset(&blocked_sig); sigdelset(&blocked_sig, SIGPROF); @@ -3146,7 +3141,7 @@ int main(int argc, char **argv) /* Create nbthread-1 thread. The first thread is the current process */ threads[0] = pthread_self(); for (i = 1; i < global.nbthread; i++) - pthread_create(&threads[i], NULL, &run_thread_poll_loop, &tids[i]); + pthread_create(&threads[i], NULL, &run_thread_poll_loop, (void *)(long)i); #ifdef USE_CPU_AFFINITY /* Now the CPU affinity for all threads */ @@ -3180,13 +3175,12 @@ int main(int argc, char **argv) haproxy_unblock_signals(); /* Finally, start the poll loop for the first thread */ - run_thread_poll_loop(&tids[0]); + run_thread_poll_loop(0); /* Wait the end of other threads */ for (i = 1; i < global.nbthread; i++) pthread_join(threads[i], NULL); - free(tids); free(threads); #if defined(DEBUG_THREAD) || defined(DEBUG_FULL) @@ -3195,8 +3189,7 @@ int main(int argc, char **argv) } #else /* ! USE_THREAD */ haproxy_unblock_signals(); - run_thread_poll_loop((int []){0}); - + run_thread_poll_loop(0); #endif /* Do some cleanup */