summaryrefslogtreecommitdiffstats
path: root/modules/nativescript/nativescript.cpp
diff options
context:
space:
mode:
authorRuslan Mustakov <r.mustakov@gmail.com>2017-08-03 14:04:04 +0700
committerRuslan Mustakov <r.mustakov@gmail.com>2017-08-03 14:04:04 +0700
commitaaf84129db62c5ab50928fc58e4011d61f6f5895 (patch)
treec86aa048d146c29cc6fac1f263b0fb813a5ee60b /modules/nativescript/nativescript.cpp
parentdaad16b7c7a10f0f1ede92899573e9e354c9d2cd (diff)
downloadredot-engine-aaf84129db62c5ab50928fc58e4011d61f6f5895.tar.gz
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 e7445e6da9..49806a8e8c 100644
--- a/modules/nativescript/nativescript.cpp
+++ b/modules/nativescript/nativescript.cpp
@@ -1057,9 +1057,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()) {
@@ -1072,44 +1084,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