summaryrefslogtreecommitdiffstats
path: root/core/object/worker_thread_pool.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2023-11-09 18:09:01 +0100
committerRémi Verschelde <rverschelde@gmail.com>2023-11-09 18:09:01 +0100
commit19db9308ffb7a3bd3d34d6be92ab08fb54f350bb (patch)
treecfd0743c921e3e622e8f84639b6964324bb7fb5d /core/object/worker_thread_pool.cpp
parentd36cc7313e3c0c8d717522964cc8c577b8a0863a (diff)
parentf3e96a85485f68ee8c3e669e4bb6c910762a9130 (diff)
downloadredot-engine-19db9308ffb7a3bd3d34d6be92ab08fb54f350bb.tar.gz
Merge pull request #84657 from RandomShaper/lang_srv_threading
Make languages bookkeeping thread-safe
Diffstat (limited to 'core/object/worker_thread_pool.cpp')
-rw-r--r--core/object/worker_thread_pool.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp
index 2fcd0867e6..784acadab4 100644
--- a/core/object/worker_thread_pool.cpp
+++ b/core/object/worker_thread_pool.cpp
@@ -30,6 +30,7 @@
#include "worker_thread_pool.h"
+#include "core/object/script_language.h"
#include "core/os/os.h"
#include "core/os/thread_safe.h"
@@ -60,6 +61,14 @@ void WorkerThreadPool::_process_task(Task *p_task) {
set_current_thread_safe_for_nodes(false);
pool_thread_index = thread_ids[Thread::get_caller_id()];
ThreadData &curr_thread = threads[pool_thread_index];
+ // Since the WorkerThreadPool is started before the script server,
+ // its pre-created threads can't have ScriptServer::thread_enter() called on them early.
+ // Therefore, we do it late at the first opportunity, so in case the task
+ // about to be run uses scripting, guarantees are held.
+ if (!curr_thread.ready_for_scripting && ScriptServer::are_languages_initialized()) {
+ ScriptServer::thread_enter();
+ curr_thread.ready_for_scripting = true;
+ }
task_mutex.lock();
p_task->pool_thread_index = pool_thread_index;
if (low_priority) {