4040
4141#include < godot_cpp/godot.hpp>
4242
43+ #if defined(MACOS_ENABLED) && defined(HOT_RELOAD_ENABLED)
44+ #include < mutex>
45+ #define _GODOT_CPP_AVOID_THREAD_LOCAL
46+ #define _GODOT_CPP_THREAD_LOCAL
47+ #else
48+ #define _GODOT_CPP_THREAD_LOCAL thread_local
49+ #endif
50+
4351namespace godot {
4452
4553class ClassDB ;
@@ -58,15 +66,22 @@ class Wrapped {
5866 template <typename T, std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value, bool >>
5967 friend _ALWAYS_INLINE_ void _pre_initialize ();
6068
61- thread_local static const StringName *_constructing_extension_class_name;
62- thread_local static const GDExtensionInstanceBindingCallbacks *_constructing_class_binding_callbacks;
69+ #ifdef _GODOT_CPP_AVOID_THREAD_LOCAL
70+ static std::recursive_mutex _constructing_mutex;
71+ #endif
72+
73+ _GODOT_CPP_THREAD_LOCAL static const StringName *_constructing_extension_class_name;
74+ _GODOT_CPP_THREAD_LOCAL static const GDExtensionInstanceBindingCallbacks *_constructing_class_binding_callbacks;
6375
6476#ifdef HOT_RELOAD_ENABLED
65- thread_local static GDExtensionObjectPtr _constructing_recreate_owner;
77+ _GODOT_CPP_THREAD_LOCAL static GDExtensionObjectPtr _constructing_recreate_owner;
6678#endif
6779
6880 template <typename T>
6981 _ALWAYS_INLINE_ static void _set_construct_info () {
82+ #ifdef _GODOT_CPP_AVOID_THREAD_LOCAL
83+ std::lock_guard<std::recursive_mutex> lk (Wrapped::_constructing_mutex);
84+ #endif
7085 _constructing_extension_class_name = T::_get_extension_class_name ();
7186 _constructing_class_binding_callbacks = &T::_gde_binding_callbacks;
7287 }
0 commit comments