MEDIUM: tasks: Mutualize the TASK_KILLED code between tasks and tasklets
The code to handle a task/tasklet when it's been killed before it were to run is mostly identical, so move it outside of task and tasklet specific code, and inside the common code. This commit is just cosmetic, and should have no impact.
This commit is contained in:
parent
4abfade371
commit
b81c9390f4
39
src/task.c
39
src/task.c
@ -613,22 +613,26 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
|
|||||||
}
|
}
|
||||||
} while (!_HA_ATOMIC_CAS(&t->state, &state, (state & TASK_PERSISTENT) | TASK_RUNNING));
|
} while (!_HA_ATOMIC_CAS(&t->state, &state, (state & TASK_PERSISTENT) | TASK_RUNNING));
|
||||||
|
|
||||||
if (t->state & TASK_F_TASKLET) {
|
if (unlikely((state & TASK_KILLED) || process == NULL)) {
|
||||||
/* this is a tasklet */
|
/* Task or tasklet has been killed, let's remove it */
|
||||||
|
if (t->state & TASK_F_TASKLET)
|
||||||
if (likely(!(state & TASK_KILLED))) {
|
|
||||||
t = process(t, ctx, state);
|
|
||||||
if (t != NULL)
|
|
||||||
_HA_ATOMIC_AND(&t->state, ~TASK_RUNNING);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pool_free(pool_head_tasklet, t);
|
pool_free(pool_head_tasklet, t);
|
||||||
|
else {
|
||||||
|
task_unlink_wq(t);
|
||||||
|
__task_free(t);
|
||||||
|
}
|
||||||
/* We don't want max_processed to be decremented if
|
/* We don't want max_processed to be decremented if
|
||||||
* we're just freeing a destroyed tasklet, we should
|
* we're just freeing a destroyed task, we should only
|
||||||
* only do so if we really ran a tasklet.
|
* do so if we really ran a task.
|
||||||
*/
|
*/
|
||||||
goto next;
|
goto next;
|
||||||
}
|
}
|
||||||
|
if (t->state & TASK_F_TASKLET) {
|
||||||
|
/* this is a tasklet */
|
||||||
|
|
||||||
|
t = process(t, ctx, state);
|
||||||
|
if (t != NULL)
|
||||||
|
_HA_ATOMIC_AND(&t->state, ~TASK_RUNNING);
|
||||||
} else {
|
} else {
|
||||||
/* This is a regular task */
|
/* This is a regular task */
|
||||||
__ha_barrier_atomic_store();
|
__ha_barrier_atomic_store();
|
||||||
@ -639,19 +643,10 @@ unsigned int run_tasks_from_lists(unsigned int budgets[])
|
|||||||
* directly free the task. Otherwise it will be seen after processing and
|
* directly free the task. Otherwise it will be seen after processing and
|
||||||
* it's freed on the exit path.
|
* it's freed on the exit path.
|
||||||
*/
|
*/
|
||||||
if (likely(!(state & TASK_KILLED) && process == process_stream))
|
if (process == process_stream)
|
||||||
t = process_stream(t, ctx, state);
|
t = process_stream(t, ctx, state);
|
||||||
else if (!(state & TASK_KILLED) && process != NULL)
|
else
|
||||||
t = process(t, ctx, state);
|
t = process(t, ctx, state);
|
||||||
else {
|
|
||||||
task_unlink_wq(t);
|
|
||||||
__task_free(t);
|
|
||||||
/* We don't want max_processed to be decremented if
|
|
||||||
* we're just freeing a destroyed task, we should only
|
|
||||||
* do so if we really ran a task.
|
|
||||||
*/
|
|
||||||
goto next;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If there is a pending state we have to wake up the task
|
/* If there is a pending state we have to wake up the task
|
||||||
* immediately, else we defer it into wait queue
|
* immediately, else we defer it into wait queue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user