From: Willy Tarreau Date: Sun, 26 Nov 2017 09:08:06 +0000 (+0100) Subject: MINOR: task: keep a pointer to the currently running task X-Git-Tag: v1.8.0~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d1222ce7392423c54be21d2c7ebf4adc87a6a5d;p=thirdparty%2Fhaproxy.git MINOR: task: keep a pointer to the currently running task 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. --- diff --git a/src/task.c b/src/task.c index c7ac813eb1..fbaaecee13 100644 --- a/src/task.c +++ b/src/task.c @@ -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; }