From f05f8c399e4737a95383b57df343a0e8c607f231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 13 Nov 2023 16:06:48 +0100 Subject: [PATCH] Let languages init & finish run without locks held --- core/object/script_language.cpp | 36 ++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 2bdbfb5ad17f..1fee23874b8a 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -223,26 +223,48 @@ void ScriptServer::init_languages() { } } + HashSet langs_to_init; { MutexLock lock(languages_mutex); - for (int i = 0; i < _language_count; i++) { - _languages[i]->init(); + if (_languages[i]) { + langs_to_init.insert(_languages[i]); + } } + } + for (ScriptLanguage *E : langs_to_init) { + E->init(); + } + + { + MutexLock lock(languages_mutex); languages_ready = true; } } void ScriptServer::finish_languages() { - MutexLock lock(languages_mutex); + HashSet langs_to_finish; - for (int i = 0; i < _language_count; i++) { - _languages[i]->finish(); + { + MutexLock lock(languages_mutex); + for (int i = 0; i < _language_count; i++) { + if (_languages[i]) { + langs_to_finish.insert(_languages[i]); + } + } + } + + for (ScriptLanguage *E : langs_to_finish) { + E->finish(); } - global_classes_clear(); - languages_ready = false; + { + MutexLock lock(languages_mutex); + languages_ready = false; + } + + global_classes_clear(); } bool ScriptServer::are_languages_initialized() {