fix race condition where task could momentarily not be in the queue when reordering

This commit is contained in:
Jamiras 2020-04-04 09:37:55 -06:00
parent 1d7cae2ceb
commit 23ba478f82
1 changed files with 16 additions and 6 deletions

View File

@ -506,18 +506,28 @@ static void threaded_worker(void *userdata)
finished = task->finished; finished = task->finished;
slock_unlock(property_lock); slock_unlock(property_lock);
slock_lock(running_lock);
task_queue_remove(&tasks_running, task);
slock_unlock(running_lock);
/* Update queue */ /* Update queue */
if (!finished) if (!finished)
{ {
/* Re-add task to running queue */ /* Move the task to the back of the queue */
retro_task_threaded_push_running(task); /* mimics retro_task_threaded_push_running, but also includes a task_queue_remove */
slock_lock(running_lock);
slock_lock(queue_lock);
if (task->next != NULL) /* do nothing if only item in queue */
{
task_queue_remove(&tasks_running, task);
task_queue_put(&tasks_running, task);
}
slock_unlock(queue_lock);
slock_unlock(running_lock);
} }
else else
{ {
/* Remove task from running queue */
slock_lock(running_lock);
task_queue_remove(&tasks_running, task);
slock_unlock(running_lock);
/* Add task to finished queue */ /* Add task to finished queue */
slock_lock(finished_lock); slock_lock(finished_lock);
task_queue_put(&tasks_finished, task); task_queue_put(&tasks_finished, task);