diff options
Diffstat (limited to 'modules/nativescript/nativescript.h')
| -rw-r--r-- | modules/nativescript/nativescript.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h index bc7a6e3ed6..c60effd0c1 100644 --- a/modules/nativescript/nativescript.h +++ b/modules/nativescript/nativescript.h @@ -41,6 +41,10 @@ #include "godot_nativescript.h" #include "modules/gdnative/gdnative.h" +#ifndef NO_THREADS +#include "os/mutex.h" +#endif + struct NativeScriptDesc { struct Method { @@ -102,6 +106,9 @@ class NativeScript : public Script { String class_name; +#ifndef NO_THREADS + Mutex *owners_lock; +#endif Set<Object *> instance_owners; protected: @@ -181,6 +188,9 @@ public: virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); + virtual void refcount_incremented(); + virtual bool refcount_decremented(); + ~NativeScriptInstance(); }; @@ -197,7 +207,23 @@ private: void _unload_stuff(); +#ifndef NO_THREADS + Mutex *mutex; + + Set<Ref<GDNativeLibrary> > libs_to_init; + Set<NativeScript *> scripts_to_register; + volatile bool has_objects_to_register; // so that we don't lock mutex every frame - it's rarely needed + void defer_init_library(Ref<GDNativeLibrary> lib, NativeScript *script); +#endif + + void init_library(const Ref<GDNativeLibrary> &lib); + void register_script(NativeScript *script); + void unregister_script(NativeScript *script); + + void call_libraries_cb(const StringName &name); + public: + // These two maps must only be touched on the main thread Map<String, Map<StringName, NativeScriptDesc> > library_classes; Map<String, Ref<GDNative> > library_gdnatives; @@ -206,6 +232,15 @@ public: const StringName _init_call_type = "nativescript_init"; const StringName _init_call_name = "godot_nativescript_init"; + const StringName _noarg_call_type = "nativescript_no_arg"; + + const StringName _frame_call_name = "godot_nativescript_frame"; + +#ifndef NO_THREADS + const StringName _thread_enter_call_name = "godot_nativescript_thread_enter"; + const StringName _thread_exit_call_name = "godot_nativescript_thread_exit"; +#endif + NativeScriptLanguage(); ~NativeScriptLanguage(); @@ -215,6 +250,13 @@ public: void _hacky_api_anchor(); +#ifndef NO_THREADS + virtual void thread_enter(); + virtual void thread_exit(); +#endif + + virtual void frame(); + virtual String get_name() const; virtual void init(); virtual String get_type() const; |