1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

WorkerThreadPool: Fix wrong sync logic breaking task map integrity

This commit is contained in:
Pedro J. Estébanez
2024-07-15 11:22:39 +02:00
parent 62d9ce6445
commit 10b543f8a7

View File

@@ -397,16 +397,17 @@ Error WorkerThreadPool::wait_for_task_completion(TaskID p_task_id) {
task->waiting_user++; task->waiting_user++;
} }
task_mutex.unlock();
if (caller_pool_thread) { if (caller_pool_thread) {
task_mutex.unlock();
_wait_collaboratively(caller_pool_thread, task); _wait_collaboratively(caller_pool_thread, task);
task_mutex.lock();
task->waiting_pool--; task->waiting_pool--;
if (task->waiting_pool == 0 && task->waiting_user == 0) { if (task->waiting_pool == 0 && task->waiting_user == 0) {
tasks.erase(p_task_id); tasks.erase(p_task_id);
task_allocator.free(task); task_allocator.free(task);
} }
} else { } else {
task_mutex.unlock();
task->done_semaphore.wait(); task->done_semaphore.wait();
task_mutex.lock(); task_mutex.lock();
task->waiting_user--; task->waiting_user--;
@@ -414,9 +415,9 @@ Error WorkerThreadPool::wait_for_task_completion(TaskID p_task_id) {
tasks.erase(p_task_id); tasks.erase(p_task_id);
task_allocator.free(task); task_allocator.free(task);
} }
task_mutex.unlock();
} }
task_mutex.unlock();
return OK; return OK;
} }