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

Let user scripts disable thread safety checks

This commit is contained in:
Pedro J. Estébanez
2023-06-08 11:33:35 +02:00
parent 828ec2c5d0
commit 2b001db76e
6 changed files with 27 additions and 2 deletions

View File

@@ -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);