summaryrefslogtreecommitdiffstats
path: root/src/classes/wrapped.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/classes/wrapped.cpp')
-rw-r--r--src/classes/wrapped.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp
index ffca4f9..3eb17ca 100644
--- a/src/classes/wrapped.cpp
+++ b/src/classes/wrapped.cpp
@@ -39,14 +39,27 @@
#include <godot_cpp/core/class_db.hpp>
namespace godot {
-thread_local const StringName *Wrapped::_constructing_extension_class_name = nullptr;
-thread_local const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr;
+
+#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL
+std::recursive_mutex Wrapped::_constructing_mutex;
+#endif
+
+_GODOT_CPP_THREAD_LOCAL const StringName *Wrapped::_constructing_extension_class_name = nullptr;
+_GODOT_CPP_THREAD_LOCAL const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr;
+
+#ifdef HOT_RELOAD_ENABLED
+_GODOT_CPP_THREAD_LOCAL GDExtensionObjectPtr Wrapped::_constructing_recreate_owner = nullptr;
+#endif
const StringName *Wrapped::_get_extension_class_name() {
return nullptr;
}
void Wrapped::_postinitialize() {
+#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL
+ Wrapped::_constructing_mutex.unlock();
+#endif
+
// Only send NOTIFICATION_POSTINITIALIZE for extension classes.
if (_is_extension_class()) {
_notificationv(Object::NOTIFICATION_POSTINITIALIZE);
@@ -55,25 +68,14 @@ void Wrapped::_postinitialize() {
Wrapped::Wrapped(const StringName p_godot_class) {
#ifdef HOT_RELOAD_ENABLED
- if (unlikely(Wrapped::recreate_instance)) {
- RecreateInstance *recreate_data = Wrapped::recreate_instance;
- RecreateInstance *previous = nullptr;
- while (recreate_data) {
- if (recreate_data->wrapper == this) {
- _owner = recreate_data->owner;
- if (previous) {
- previous->next = recreate_data->next;
- } else {
- Wrapped::recreate_instance = recreate_data->next;
- }
- return;
- }
- previous = recreate_data;
- recreate_data = recreate_data->next;
- }
- }
+ if (unlikely(Wrapped::_constructing_recreate_owner)) {
+ _owner = Wrapped::_constructing_recreate_owner;
+ Wrapped::_constructing_recreate_owner = nullptr;
+ } else
#endif
- _owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
+ {
+ _owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr()));
+ }
if (_constructing_extension_class_name) {
godot::internal::gdextension_interface_object_set_instance(_owner, reinterpret_cast<GDExtensionConstStringNamePtr>(_constructing_extension_class_name), this);