Merge pull request #77234 from RandomShaper/fix_rtl_mt

Allow threads to mark themselves as safe for nodes
This commit is contained in:
Rémi Verschelde
2023-05-24 08:42:59 +02:00
7 changed files with 62 additions and 4 deletions
+4 -4
View File
@@ -543,7 +543,7 @@ public:
if (current_process_thread_group == nullptr) {
// Not thread processing. Only accessible if node is outside the scene tree,
// if accessing from the main thread or being loaded.
return !data.inside_tree || Thread::is_main_thread() || ResourceLoader::is_within_load();
return !data.inside_tree || is_current_thread_safe_for_nodes();
} else {
// Thread processing
return current_process_thread_group == data.process_thread_group_owner;
@@ -552,7 +552,7 @@ public:
_FORCE_INLINE_ bool is_readable_from_caller_thread() const {
if (current_process_thread_group == nullptr) {
return Thread::is_main_thread() || ResourceLoader::is_within_load();
return Thread::is_main_thread() || is_current_thread_safe_for_nodes();
} else {
return true;
}
@@ -731,8 +731,8 @@ Error Node::rpc_id(int p_peer_id, const StringName &p_method, VarArgs... p_args)
#ifdef DEBUG_ENABLED
#define ERR_THREAD_GUARD ERR_FAIL_COND_MSG(!is_accessible_from_caller_thread(), "Caller thread can't call this function in this node. Use call_deferred() or call_thread_group() instead.");
#define ERR_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(!is_accessible_from_caller_thread(), (m_ret), "Caller thread can't call this function in this node. Use call_deferred() or call_thread_group() instead.")
#define ERR_MAIN_THREAD_GUARD ERR_FAIL_COND_MSG(is_inside_tree() && !Thread::is_main_thread(), "This function in this node can only be accessed from the main thread. Use call_deferred() instead.");
#define ERR_MAIN_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(is_inside_tree() && !Thread::is_main_thread(), (m_ret), "This function in this node can only be accessed from the main thread. Use call_deferred() instead.")
#define ERR_MAIN_THREAD_GUARD ERR_FAIL_COND_MSG(is_inside_tree() && !is_current_thread_safe_for_nodes(), "This function in this node can only be accessed from the main thread. Use call_deferred() instead.");
#define ERR_MAIN_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(is_inside_tree() && !is_current_thread_safe_for_nodes(), (m_ret), "This function in this node can only be accessed from the main thread. Use call_deferred() instead.")
#define ERR_READ_THREAD_GUARD ERR_FAIL_COND_MSG(!is_readable_from_caller_thread(), "This function in this node can only be accessed from either the main thread or a thread group. Use call_deferred() instead.")
#define ERR_READ_THREAD_GUARD_V(m_ret) ERR_FAIL_COND_V_MSG(!is_readable_from_caller_thread(), (m_ret), "This function in this node can only be accessed from either the main thread or a thread group. Use call_deferred() instead.")
#else