]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: remove __tasklet_remove_from_tasklet_list()
authorWilly Tarreau <w@1wt.eu>
Mon, 30 Nov 2020 13:52:11 +0000 (14:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 30 Nov 2020 17:17:44 +0000 (18:17 +0100)
This function is only used at a single place directly within the
scheduler in run_tasks_from_lists() and it really ought not be called
by anything else, regardless of what its comment says. Let's delete
it, move the two lines directly into the call place, and take this
opportunity to factor the atomic decrement on tasks_run_queue. A comment
was added on the remaining one tasklet_remove_from_tasklet_list() to
mention the risks in using it.

include/haproxy/task.h
src/task.c

index e4c93fc4aa2cc91f17b1640f93042261df828b3b..d5cf3b15750b6b312f1b8aa7f7958630d3b519ba 100644 (file)
@@ -369,18 +369,9 @@ static inline void tasklet_wakeup(struct tasklet *tl)
        tasklet_wakeup_on(tl, tl->tid);
 }
 
-/* Remove the tasklet from the tasklet list. The tasklet MUST already be there.
- * If unsure, use tasklet_remove_from_tasklet_list() instead. If used with a
- * plain task, the caller must update the task_list_size.
- * This should only be used by the thread that owns the tasklet, any other
- * thread should use tasklet_cancel().
+/* Try to remove a tasklet from the list. This call is inherently racy and may
+ * only be performed on the thread that was supposed to dequeue this tasklet.
  */
-static inline void __tasklet_remove_from_tasklet_list(struct tasklet *t)
-{
-       LIST_DEL_INIT(&t->list);
-       _HA_ATOMIC_SUB(&tasks_run_queue, 1);
-}
-
 static inline void tasklet_remove_from_tasklet_list(struct tasklet *t)
 {
        if (MT_LIST_DEL((struct mt_list *)&t->list))
index 93e30227dae13a48808e223301d60921c6b044ae..d1e06ce2b46985348e135cd2e1881c86cc7428a0 100644 (file)
@@ -458,10 +458,12 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
                t->calls++;
                sched->current = t;
 
+               _HA_ATOMIC_SUB(&tasks_run_queue, 1);
+
                if (TASK_IS_TASKLET(t)) {
                        state = _HA_ATOMIC_XCHG(&t->state, state);
                        __ha_barrier_atomic_store();
-                       __tasklet_remove_from_tasklet_list((struct tasklet *)t);
+                       LIST_DEL_INIT(&((struct tasklet *)t)->list);
                        process(t, ctx, state);
                        done++;
                        sched->current = NULL;
@@ -471,7 +473,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
 
                state = _HA_ATOMIC_XCHG(&t->state, state | TASK_RUNNING);
                __ha_barrier_atomic_store();
-               __tasklet_remove_from_tasklet_list((struct tasklet *)t);
+               LIST_DEL_INIT(&((struct tasklet *)t)->list);
 
                /* OK then this is a regular task */