summaryrefslogtreecommitdiffstats
path: root/modules/nativescript/nativescript.cpp
diff options
context:
space:
mode:
authorThomas Herzog <thomas.herzog@mail.com>2017-08-03 13:52:44 +0200
committerGitHub <noreply@github.com>2017-08-03 13:52:44 +0200
commit056b5f9e56e6abfe1777e9bfafbb69e8d0a8ec21 (patch)
tree1d4e70b9456298f42351225ce18599694ed60374 /modules/nativescript/nativescript.cpp
parentc936e9946eaf68d4b37b713fbfe512278cca278c (diff)
parentaaf84129db62c5ab50928fc58e4011d61f6f5895 (diff)
downloadredot-engine-056b5f9e56e6abfe1777e9bfafbb69e8d0a8ec21.tar.gz
Merge pull request #10060 from endragor/nativescript-frame
Forward frame call to GDNative libraries
Diffstat (limited to 'modules/nativescript/nativescript.cpp')
-rw-r--r--modules/nativescript/nativescript.cpp52
1 files changed, 19 insertions, 33 deletions
diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp
index ad746c9546..226b5effa9 100644
--- a/modules/nativescript/nativescript.cpp
+++ b/modules/nativescript/nativescript.cpp
@@ -1052,9 +1052,21 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
#endif
}
-#ifndef NO_THREADS
+void NativeScriptLanguage::call_libraries_cb(const StringName &name) {
+ // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
+ for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
+ L->get()->call_native_raw(
+ _noarg_call_type,
+ name,
+ NULL,
+ 0,
+ NULL,
+ NULL);
+ }
+}
void NativeScriptLanguage::frame() {
+#ifndef NO_THREADS
if (has_objects_to_register) {
MutexLock lock(mutex);
for (Set<Ref<GDNativeLibrary> >::Element *L = libs_to_init.front(); L; L = L->next()) {
@@ -1067,44 +1079,18 @@ void NativeScriptLanguage::frame() {
scripts_to_register.clear();
has_objects_to_register = false;
}
+#endif
+ call_libraries_cb(_frame_call_name);
}
+#ifndef NO_THREADS
+
void NativeScriptLanguage::thread_enter() {
- Vector<Ref<GDNative> > libs;
- {
- MutexLock lock(mutex);
- for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
- libs.push_back(L->get());
- }
- }
- for (int i = 0; i < libs.size(); ++i) {
- libs[i]->call_native_raw(
- _thread_cb_call_type,
- _thread_enter_call_name,
- NULL,
- 0,
- NULL,
- NULL);
- }
+ call_libraries_cb(_thread_enter_call_name);
}
void NativeScriptLanguage::thread_exit() {
- Vector<Ref<GDNative> > libs;
- {
- MutexLock lock(mutex);
- for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
- libs.push_back(L->get());
- }
- }
- for (int i = 0; i < libs.size(); ++i) {
- libs[i]->call_native_raw(
- _thread_cb_call_type,
- _thread_exit_call_name,
- NULL,
- 0,
- NULL,
- NULL);
- }
+ call_libraries_cb(_thread_exit_call_name);
}
#endif // NO_THREADS