]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: task: keep a pointer to the currently running task
authorWilly Tarreau <w@1wt.eu>
Sun, 26 Nov 2017 09:08:06 +0000 (10:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 26 Nov 2017 10:10:50 +0000 (11:10 +0100)
Very often when debugging, the current task's pointer isn't easy to
recover (eg: from a core file). Let's keep a copy of it, it will
likely help, especially with threads.

src/task.c

index c7ac813eb17b18788a5441415a25cf809412c4d6..fbaaecee138f7e7fdbbbd11aefdc35344237cfe9 100644 (file)
@@ -38,6 +38,8 @@ unsigned int tasks_run_queue_cur = 0;    /* copy of the run queue size */
 unsigned int nb_tasks_cur = 0;     /* copy of the tasks count */
 unsigned int niced_tasks = 0;      /* number of niced tasks in the run queue */
 
+THREAD_LOCAL struct task *curr_task = NULL; /* task currently running or NULL */
+
 __decl_hathreads(HA_SPINLOCK_T rq_lock); /* spin lock related to run queue */
 __decl_hathreads(HA_SPINLOCK_T wq_lock); /* spin lock related to wait queue */
 
@@ -217,6 +219,7 @@ void process_runnable_tasks()
                        t->pending_state = 0;
 
                        t->calls++;
+                       curr_task = t;
                        /* This is an optimisation to help the processor's branch
                         * predictor take this most common call.
                         */
@@ -224,6 +227,7 @@ void process_runnable_tasks()
                                t = process_stream(t);
                        else
                                t = t->process(t);
+                       curr_task = NULL;
 
                        if (likely(t != NULL)) {
                                t->state &= ~TASK_RUNNING;
@@ -298,10 +302,12 @@ void process_runnable_tasks()
                        /* This is an optimisation to help the processor's branch
                         * predictor take this most common call.
                         */
+                       curr_task = t;
                        if (likely(t->process == process_stream))
                                t = process_stream(t);
                        else
                                t = t->process(t);
+                       curr_task = NULL;
                        if (t)
                                local_tasks[final_tasks_count++] = t;
                }