From: Willy Tarreau Date: Fri, 2 May 2025 08:55:43 +0000 (+0200) Subject: CLEANUP: tasks: use the local state, not t->state, to check for tasklets X-Git-Tag: v3.2-dev14~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ed238101aaf0bd944aa112501dd5a1ba631cb9a;p=thirdparty%2Fhaproxy.git CLEANUP: tasks: use the local state, not t->state, to check for tasklets There's no point reading t->state to check for a tasklet after we've atomically read the state into the local "state" variable. Not only it's more expensive, it's also less clear whether that state is supposed to be atomic or not. And in any case, tasks and tasklets have their type forever and the one reflected in state is correct and stable. --- diff --git a/src/task.c b/src/task.c index 843e46790..d2c8f9b58 100644 --- a/src/task.c +++ b/src/task.c @@ -616,7 +616,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[]) __ha_barrier_atomic_store(); /* keep the task counter up to date */ - if (!(t->state & TASK_F_TASKLET)) + if (!(state & TASK_F_TASKLET)) _HA_ATOMIC_DEC(&ha_thread_ctx[tid].tasks_in_list); /* From this point, we know that the task or tasklet was properly @@ -628,7 +628,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[]) if (unlikely((state & TASK_KILLED) || process == NULL)) { /* Task or tasklet has been killed, let's remove it */ - if (t->state & TASK_F_TASKLET) + if (state & TASK_F_TASKLET) pool_free(pool_head_tasklet, t); else { task_unlink_wq(t); @@ -642,7 +642,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[]) } /* OK now the task or tasklet is well alive and is going to be run */ - if (t->state & TASK_F_TASKLET) { + if (state & TASK_F_TASKLET) { /* this is a tasklet */ t = process(t, ctx, state);