diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 8 | ||||
-rw-r--r-- | core/core_bind.h | 2 | ||||
-rw-r--r-- | core/io/resource_loader.cpp | 1 | ||||
-rw-r--r-- | core/object/worker_thread_pool.cpp | 4 |
4 files changed, 14 insertions, 1 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 8771aa88cc..bb42b272d7 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -39,6 +39,7 @@ #include "core/math/geometry_2d.h" #include "core/math/geometry_3d.h" #include "core/os/keyboard.h" +#include "core/os/thread_safe.h" #include "core/variant/typed_array.h" namespace core_bind { @@ -1255,6 +1256,11 @@ Variant Thread::wait_to_finish() { return r; } +void Thread::set_thread_safety_checks_enabled(bool p_enabled) { + ERR_FAIL_COND_MSG(::Thread::is_main_thread(), "This call is forbidden on the main thread."); + set_current_thread_safe_for_nodes(!p_enabled); +} + void Thread::_bind_methods() { ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL)); ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id); @@ -1262,6 +1268,8 @@ void Thread::_bind_methods() { ClassDB::bind_method(D_METHOD("is_alive"), &Thread::is_alive); ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish); + ClassDB::bind_static_method("Thread", D_METHOD("set_thread_safety_checks_enabled", "enabled"), &Thread::set_thread_safety_checks_enabled); + BIND_ENUM_CONSTANT(PRIORITY_LOW); BIND_ENUM_CONSTANT(PRIORITY_NORMAL); BIND_ENUM_CONSTANT(PRIORITY_HIGH); diff --git a/core/core_bind.h b/core/core_bind.h index 55c365eb7c..6b25510b14 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -408,6 +408,8 @@ public: bool is_started() const; bool is_alive() const; Variant wait_to_finish(); + + static void set_thread_safety_checks_enabled(bool p_enabled); }; namespace special { diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index ac1870fe88..525c41cf87 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -358,7 +358,6 @@ void ResourceLoader::_thread_load_function(void *p_userdata) { if (load_nesting == 0 && mq_override) { memdelete(mq_override); - set_current_thread_safe_for_nodes(false); } } diff --git a/core/object/worker_thread_pool.cpp b/core/object/worker_thread_pool.cpp index afe6ecd1b3..d285be3e70 100644 --- a/core/object/worker_thread_pool.cpp +++ b/core/object/worker_thread_pool.cpp @@ -31,6 +31,7 @@ #include "worker_thread_pool.h" #include "core/os/os.h" +#include "core/os/thread_safe.h" void WorkerThreadPool::Task::free_template_userdata() { ERR_FAIL_COND(!template_userdata); @@ -178,6 +179,9 @@ void WorkerThreadPool::_process_task(Task *p_task) { if (post) { task_available_semaphore.post(); } + + // Engine/user tasks can set-and-forget, so we must be sure it's back to normal by the end of the task. + set_current_thread_safe_for_nodes(false); } } |