]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: tasks: Mutualize code between tasks and tasklets.
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 29 Apr 2025 13:15:01 +0000 (15:15 +0200)
committerOlivier Houchard <cognet@ci0.org>
Wed, 30 Apr 2025 15:08:57 +0000 (17:08 +0200)
The code that checks if we're currently running, and waits if so, was
identical between tasks and tasklets, so move it in code common to tasks
and tasklets.
This commit is just cosmetic, and should not have any impact.

src/task.c

index e0e6dcf202e56bf64553e8c20b02d06ae5428d35..50391bc3f282904520d26186ad363e5ece294837 100644 (file)
@@ -597,16 +597,24 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                LIST_DEL_INIT(&((struct tasklet *)t)->list);
                __ha_barrier_store();
 
+
+               /* We must be the exclusive owner of the TASK_RUNNING bit, and
+                * have to be careful that the task is not being manipulated on
+                * another thread finding it expired in wake_expired_tasks().
+                * The TASK_RUNNING bit will be set during these operations,
+                * they are extremely rare and do not last long so the best to
+                * do here is to wait.
+                */
+               state = _HA_ATOMIC_LOAD(&t->state);
+               do {
+                       while (unlikely(state & TASK_RUNNING)) {
+                               __ha_cpu_relax();
+                               state = _HA_ATOMIC_LOAD(&t->state);
+                       }
+               } while (!_HA_ATOMIC_CAS(&t->state, &state, (state & TASK_PERSISTENT) | TASK_RUNNING));
+
                if (t->state & TASK_F_TASKLET) {
                        /* this is a tasklet */
-                       state = _HA_ATOMIC_LOAD(&t->state);
-                       do {
-                               while (unlikely(state & TASK_RUNNING)) {
-                                       __ha_cpu_relax();
-                                       state = _HA_ATOMIC_LOAD(&t->state);
-                               }
-                       } while (!_HA_ATOMIC_CAS(&t->state, &state, (state & TASK_PERSISTENT) | TASK_RUNNING));
-
 
                        if (likely(!(state & TASK_KILLED))) {
                                t = process(t, ctx, state);
@@ -626,22 +634,6 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                        }
                } else {
                        /* This is a regular task */
-
-                       /* We must be the exclusive owner of the TASK_RUNNING bit, and
-                        * have to be careful that the task is not being manipulated on
-                        * another thread finding it expired in wake_expired_tasks().
-                        * The TASK_RUNNING bit will be set during these operations,
-                        * they are extremely rare and do not last long so the best to
-                        * do here is to wait.
-                        */
-                       state = _HA_ATOMIC_LOAD(&t->state);
-                       do {
-                               while (unlikely(state & TASK_RUNNING)) {
-                                       __ha_cpu_relax();
-                                       state = _HA_ATOMIC_LOAD(&t->state);
-                               }
-                       } while (!_HA_ATOMIC_CAS(&t->state, &state, (state & TASK_PERSISTENT) | TASK_RUNNING));
-
                        __ha_barrier_atomic_store();
 
                        _HA_ATOMIC_DEC(&ha_thread_ctx[tid].tasks_in_list);