MINOR: task: add an application specific flag to the state: TASK_F_USR1
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Mar 2021 15:26:05 +0000 (16:26 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 10 Mar 2021 14:11:16 +0000 (15:11 +0100)
This flag will be usable by any application. It will be preserved across
wakeups so the application can use it to do various stuff. Some I/O
handlers will soon benefit from this.

(cherry picked from commit 6fa8bcdc785c29cd3a29c14d2038f38b5547eff0)
[wt: needed for upcoming fixes. task->state is 16-bit in 2.3 and before
 so we've reused bit 15 which was still available there. Ctx adjusments
 since no TASK_F_TASKLET here]
Signed-off-by: Willy Tarreau <w@1wt.eu>

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

index f37f19d..f24d9f8 100644 (file)
@@ -55,6 +55,8 @@
                            TASK_WOKEN_IO|TASK_WOKEN_SIGNAL|TASK_WOKEN_MSG| \
                            TASK_WOKEN_RES)
 
+#define TASK_F_USR1       0x80000  /* preserved user flag 1, application-specific, def:0 */
+
 enum {
        TL_URGENT = 0,   /* urgent tasklets (I/O callbacks) */
        TL_NORMAL = 1,   /* normal tasks */
index 8689da8..20b08ea 100644 (file)
@@ -450,7 +450,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
 
                budgets[queue]--;
                t = (struct task *)LIST_ELEM(tl_queues[queue].n, struct tasklet *, list);
-               state = t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING|TASK_HEAVY|TASK_KILLED);
+               state = t->state & (TASK_SHARED_WQ|TASK_SELF_WAKING|TASK_HEAVY|TASK_KILLED|TASK_F_USR1);
 
                if (state & TASK_HEAVY) {
                        /* This is a heavy task. We'll call no more than one
@@ -488,7 +488,7 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
 
                LIST_DEL_INIT(&((struct tasklet *)t)->list);
                __ha_barrier_store();
-               state = _HA_ATOMIC_XCHG(&t->state, state | TASK_RUNNING);
+               state = _HA_ATOMIC_XCHG(&t->state, state|TASK_RUNNING|TASK_F_USR1);
                __ha_barrier_atomic_store();
 
                /* OK then this is a regular task */