From 91833c852e47a83ed01deb26213b9d3184de736d Mon Sep 17 00:00:00 2001 From: David Snopek Date: Tue, 17 Sep 2024 14:53:39 -0500 Subject: Avoid `thread_local` on MacOS to prevent issues with hot reload --- src/classes/wrapped.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/classes') diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index d397d46..3eb17ca 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -39,11 +39,16 @@ #include 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 -thread_local GDExtensionObjectPtr Wrapped::_constructing_recreate_owner = nullptr; +_GODOT_CPP_THREAD_LOCAL GDExtensionObjectPtr Wrapped::_constructing_recreate_owner = nullptr; #endif const StringName *Wrapped::_get_extension_class_name() { @@ -51,6 +56,10 @@ const StringName *Wrapped::_get_extension_class_name() { } 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); -- cgit v1.2.3