]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tasks: Start using __task_set_state_and_tid()
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 11 Jun 2026 14:29:03 +0000 (16:29 +0200)
committerOlivier Houchard <cognet@ci0.org>
Fri, 12 Jun 2026 09:49:09 +0000 (11:49 +0200)
Start using __task_set_state_and_tid() when we're changing the state of
the task while queueing it, in preparation to the future ownership
changes.

include/haproxy/task.h

index 8608f6fdae1f8dd51845959dc1176f080eb1053d..6f76e43a856b5e836b3da7ca4b8227bbe7fdef9e 100644 (file)
@@ -291,7 +291,9 @@ static inline void _task_wakeup(struct task *t, unsigned int f, const struct ha_
 
        state = _HA_ATOMIC_OR_FETCH(&t->state, f);
        while (!(state & (TASK_RUNNING | TASK_QUEUED))) {
-               if (_HA_ATOMIC_CAS(&t->state, &state, state | TASK_QUEUED)) {
+               int expected_tid = _HA_ATOMIC_LOAD(&t->tid);
+
+               if (__task_set_state_and_tid(t, expected_tid, __task_get_new_tid_field(expected_tid), state, state | TASK_QUEUED)) {
                        if (likely(caller)) {
                                caller = HA_ATOMIC_XCHG(&t->caller, caller);
                                BUG_ON((ulong)caller & 1);
@@ -302,6 +304,7 @@ static inline void _task_wakeup(struct task *t, unsigned int f, const struct ha_
                        __task_wakeup(t);
                        break;
                }
+               state = _HA_ATOMIC_LOAD(&t->state);
        }
 }
 
@@ -316,14 +319,23 @@ static inline void task_drop_running(struct task *t, unsigned int f)
 {
        unsigned int state, new_state;
 
-       state = _HA_ATOMIC_LOAD(&t->state);
 
        while (1) {
-               new_state = state | f;
+               int cur_tid, new_tid;
+
+               state = _HA_ATOMIC_LOAD(&t->state);
+               new_state = (state | f) &~ TASK_RUNNING;
                if (new_state & TASK_WOKEN_ANY)
                        new_state |= TASK_QUEUED;
 
-               if (_HA_ATOMIC_CAS(&t->state, &state, new_state & ~TASK_RUNNING))
+               cur_tid = t->tid;
+
+               if ((new_state & TASK_QUEUED) || cur_tid >= 0)
+                       new_tid = cur_tid;
+               else
+                       new_tid = -1;
+
+               if (__task_set_state_and_tid(t, cur_tid, new_tid, state, new_state))
                        break;
                __ha_cpu_relax();
        }