summaryrefslogtreecommitdiffstats
path: root/modules/nativescript/nativescript.h
diff options
context:
space:
mode:
authorThomas Herzog <thomas.herzog@mail.com>2017-07-26 16:01:43 +0200
committerGitHub <noreply@github.com>2017-07-26 16:01:43 +0200
commit2b99bd492b36ee75406f15e10e63acc6a70e650a (patch)
tree3cffd003de93f69ff9c90ed567cdc533e6da60bc /modules/nativescript/nativescript.h
parent9caf9fa76f93a689d63d89ef53d6dd5af42a8c0c (diff)
parent7f32023a1ac60b62bd0159a542c25fdad0864dba (diff)
downloadredot-engine-2b99bd492b36ee75406f15e10e63acc6a70e650a.tar.gz
Merge pull request #9867 from endragor/nativescript-threading
Support multithreading for NativeScriptLanguage
Diffstat (limited to 'modules/nativescript/nativescript.h')
-rw-r--r--modules/nativescript/nativescript.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h
index bc7a6e3ed6..cf3a64e9b8 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 {
@@ -197,6 +201,19 @@ 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);
+
public:
Map<String, Map<StringName, NativeScriptDesc> > library_classes;
Map<String, Ref<GDNative> > library_gdnatives;
@@ -206,6 +223,10 @@ public:
const StringName _init_call_type = "nativescript_init";
const StringName _init_call_name = "godot_nativescript_init";
+ const StringName _thread_cb_call_type = "godot_nativescript_thread_cb";
+ const StringName _thread_enter_call_name = "godot_nativescript_thread_enter";
+ const StringName _thread_exit_call_name = "godot_nativescript_thread_exit";
+
NativeScriptLanguage();
~NativeScriptLanguage();
@@ -215,6 +236,13 @@ public:
void _hacky_api_anchor();
+#ifndef NO_THREADS
+ virtual void thread_enter();
+ virtual void thread_exit();
+
+ virtual void frame();
+#endif
+
virtual String get_name() const;
virtual void init();
virtual String get_type() const;