Browse Source

GDScript: Avoid deadlock possibility in multi-threaded load

Pedro J. Estébanez 1 year ago
parent
commit
d334632908
1 changed files with 4 additions and 0 deletions
  1. 4 0
      modules/gdscript/gdscript_cache.cpp

+ 4 - 0
modules/gdscript/gdscript_cache.cpp

@@ -344,7 +344,11 @@ Ref<GDScript> GDScriptCache::get_full_script(const String &p_path, Error &r_erro
 		}
 		}
 	}
 	}
 
 
+	// Allowing lifting the lock might cause a script to be reloaded multiple times,
+	// which, as a last resort deadlock prevention strategy, is a good tradeoff.
+	uint32_t allowance_id = WorkerThreadPool::thread_enter_unlock_allowance_zone(&singleton->mutex);
 	r_error = script->reload(true);
 	r_error = script->reload(true);
+	WorkerThreadPool::thread_exit_unlock_allowance_zone(allowance_id);
 	if (r_error) {
 	if (r_error) {
 		return script;
 		return script;
 	}
 	}