From aaf84129db62c5ab50928fc58e4011d61f6f5895 Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Thu, 3 Aug 2017 14:04:04 +0700 Subject: Forward frame call to GDNative libraries --- modules/nativescript/nativescript.cpp | 52 +++++++++++++---------------------- 1 file changed, 19 insertions(+), 33 deletions(-) (limited to 'modules/nativescript/nativescript.cpp') 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 >::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 >::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 > libs; - { - MutexLock lock(mutex); - for (Map >::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 > libs; - { - MutexLock lock(mutex); - for (Map >::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 -- cgit v1.2.3