mirror of
https://github.com/godotengine/godot
synced 2024-10-14 21:07:55 +00:00
WorkerThreadPool: Fix yield-over for not-yet-started tasks
This commit is contained in:
parent
2efbc6bfb3
commit
8192d1cbc7
|
@ -72,6 +72,9 @@ void WorkerThreadPool::_process_task(Task *p_task) {
|
||||||
p_task->pool_thread_index = pool_thread_index;
|
p_task->pool_thread_index = pool_thread_index;
|
||||||
prev_task = curr_thread.current_task;
|
prev_task = curr_thread.current_task;
|
||||||
curr_thread.current_task = p_task;
|
curr_thread.current_task = p_task;
|
||||||
|
if (p_task->pending_notify_yield_over) {
|
||||||
|
curr_thread.yield_is_over = true;
|
||||||
|
}
|
||||||
task_mutex.unlock();
|
task_mutex.unlock();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -491,7 +494,11 @@ void WorkerThreadPool::notify_yield_over(TaskID p_task_id) {
|
||||||
ERR_FAIL_MSG("Invalid Task ID.");
|
ERR_FAIL_MSG("Invalid Task ID.");
|
||||||
}
|
}
|
||||||
Task *task = *taskp;
|
Task *task = *taskp;
|
||||||
if (task->completed) {
|
if (task->pool_thread_index == -1) { // Completed or not started yet.
|
||||||
|
if (!task->completed) {
|
||||||
|
// This avoids a race condition where a task is created and yield-over called before it's processed.
|
||||||
|
task->pending_notify_yield_over = true;
|
||||||
|
}
|
||||||
task_mutex.unlock();
|
task_mutex.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ private:
|
||||||
void *native_func_userdata = nullptr;
|
void *native_func_userdata = nullptr;
|
||||||
String description;
|
String description;
|
||||||
Semaphore done_semaphore; // For user threads awaiting.
|
Semaphore done_semaphore; // For user threads awaiting.
|
||||||
bool completed = false;
|
bool completed : 1;
|
||||||
|
bool pending_notify_yield_over : 1;
|
||||||
Group *group = nullptr;
|
Group *group = nullptr;
|
||||||
SelfList<Task> task_elem;
|
SelfList<Task> task_elem;
|
||||||
uint32_t waiting_pool = 0;
|
uint32_t waiting_pool = 0;
|
||||||
|
@ -92,6 +93,8 @@ private:
|
||||||
|
|
||||||
void free_template_userdata();
|
void free_template_userdata();
|
||||||
Task() :
|
Task() :
|
||||||
|
completed(false),
|
||||||
|
pending_notify_yield_over(false),
|
||||||
task_elem(this) {}
|
task_elem(this) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue