diff options
Diffstat (limited to 'modules/gdnative')
-rw-r--r-- | modules/gdnative/nativescript/nativescript.cpp | 61 | ||||
-rw-r--r-- | modules/gdnative/nativescript/nativescript.h | 12 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_language.cpp | 25 | ||||
-rw-r--r-- | modules/gdnative/pluginscript/pluginscript_language.h | 2 |
4 files changed, 17 insertions, 83 deletions
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index 8240ae2f83..0ec6ad71d9 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -222,15 +222,11 @@ ScriptInstance *NativeScript::instance_create(Object *p_this) { nsi->userdata = script_data->create_func.create_func((godot_object *)p_this, script_data->create_func.method_data); #endif -#ifndef NO_THREADS - owners_lock->lock(); -#endif - - instance_owners.insert(p_this); + { + MutexLock lock(owners_lock); -#ifndef NO_THREADS - owners_lock->unlock(); -#endif + instance_owners.insert(p_this); + } return nsi; } @@ -782,17 +778,10 @@ NativeScript::NativeScript() { library = Ref<GDNative>(); lib_path = ""; class_name = ""; -#ifndef NO_THREADS - owners_lock = Mutex::create(); -#endif } NativeScript::~NativeScript() { NSL->unregister_script(this); - -#ifndef NO_THREADS - memdelete(owners_lock); -#endif } #define GET_SCRIPT_DESC() script->get_script_desc() @@ -1140,16 +1129,9 @@ NativeScriptInstance::~NativeScriptInstance() { script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata); if (owner) { - -#ifndef NO_THREADS - script->owners_lock->lock(); -#endif + MutexLock lock(script->owners_lock); script->instance_owners.erase(owner); - -#ifndef NO_THREADS - script->owners_lock->unlock(); -#endif } } @@ -1246,7 +1228,6 @@ NativeScriptLanguage::NativeScriptLanguage() { NativeScriptLanguage::singleton = this; #ifndef NO_THREADS has_objects_to_register = false; - mutex = Mutex::create(); #endif #ifdef DEBUG_ENABLED @@ -1283,10 +1264,6 @@ NativeScriptLanguage::~NativeScriptLanguage() { NSL->library_classes.clear(); NSL->library_gdnatives.clear(); NSL->library_script_users.clear(); - -#ifndef NO_THREADS - memdelete(mutex); -#endif } String NativeScriptLanguage::get_name() const { @@ -1413,9 +1390,7 @@ void NativeScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_ void NativeScriptLanguage::profiling_start() { #ifdef DEBUG_ENABLED -#ifndef NO_THREADS MutexLock lock(mutex); -#endif profile_data.clear(); profiling = true; @@ -1424,9 +1399,7 @@ void NativeScriptLanguage::profiling_start() { void NativeScriptLanguage::profiling_stop() { #ifdef DEBUG_ENABLED -#ifndef NO_THREADS MutexLock lock(mutex); -#endif profiling = false; #endif @@ -1434,9 +1407,8 @@ void NativeScriptLanguage::profiling_stop() { int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { #ifdef DEBUG_ENABLED -#ifndef NO_THREADS MutexLock lock(mutex); -#endif + int current = 0; for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { @@ -1458,9 +1430,8 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { #ifdef DEBUG_ENABLED -#ifndef NO_THREADS MutexLock lock(mutex); -#endif + int current = 0; for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { @@ -1484,9 +1455,7 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p_time) { #ifdef DEBUG_ENABLED -#ifndef NO_THREADS MutexLock lock(mutex); -#endif Map<StringName, ProfileData>::Element *d = profile_data.find(p_signature); if (d) { @@ -1705,9 +1674,8 @@ void NativeScriptLanguage::defer_init_library(Ref<GDNativeLibrary> lib, NativeSc #endif void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { -#ifndef NO_THREADS MutexLock lock(mutex); -#endif + // See if this library was "registered" already. const String &lib_path = lib->get_current_library_path(); ERR_FAIL_COND_MSG(lib_path.length() == 0, lib->get_name() + " does not have a library for the current platform."); @@ -1743,16 +1711,14 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { } void NativeScriptLanguage::register_script(NativeScript *script) { -#ifndef NO_THREADS MutexLock lock(mutex); -#endif + library_script_users[script->lib_path].insert(script); } void NativeScriptLanguage::unregister_script(NativeScript *script) { -#ifndef NO_THREADS MutexLock lock(mutex); -#endif + Map<String, Set<NativeScript *> >::Element *S = library_script_users.find(script->lib_path); if (S) { S->get().erase(script); @@ -1803,9 +1769,7 @@ void NativeScriptLanguage::frame() { #ifdef DEBUG_ENABLED { -#ifndef NO_THREADS MutexLock lock(mutex); -#endif for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { d->get().last_frame_call_count = d->get().frame_call_count; @@ -1867,9 +1831,7 @@ void NativeReloadNode::_notification(int p_what) { if (unloaded) break; -#ifndef NO_THREADS MutexLock lock(NSL->mutex); -#endif NSL->_unload_stuff(true); for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { @@ -1904,9 +1866,8 @@ void NativeReloadNode::_notification(int p_what) { if (!unloaded) break; -#ifndef NO_THREADS MutexLock lock(NSL->mutex); -#endif + Set<StringName> libs_to_remove; for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index 609ffa2bd4..04670b952b 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -35,6 +35,7 @@ #include "core/io/resource_saver.h" #include "core/oa_hash_map.h" #include "core/ordered_hash_map.h" +#include "core/os/mutex.h" #include "core/os/thread_safe.h" #include "core/resource.h" #include "core/script_language.h" @@ -44,10 +45,6 @@ #include "modules/gdnative/gdnative.h" #include <nativescript/godot_nativescript.h> -#ifndef NO_THREADS -#include "core/os/mutex.h" -#endif - struct NativeScriptDesc { struct Method { @@ -127,9 +124,7 @@ class NativeScript : public Script { String script_class_name; String script_class_icon_path; -#ifndef NO_THREADS - Mutex *owners_lock; -#endif + Mutex owners_lock; Set<Object *> instance_owners; protected: @@ -266,9 +261,8 @@ private: void _unload_stuff(bool p_reload = false); + Mutex mutex; #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 diff --git a/modules/gdnative/pluginscript/pluginscript_language.cpp b/modules/gdnative/pluginscript/pluginscript_language.cpp index 4e39f4b0a8..a40b59bb2e 100644 --- a/modules/gdnative/pluginscript/pluginscript_language.cpp +++ b/modules/gdnative/pluginscript/pluginscript_language.cpp @@ -399,39 +399,18 @@ void PluginScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool } void PluginScriptLanguage::lock() { -#ifndef NO_THREADS - if (_lock) { - _lock->lock(); - } -#endif + _lock.lock(); } void PluginScriptLanguage::unlock() { -#ifndef NO_THREADS - if (_lock) { - _lock->unlock(); - } -#endif + _lock.unlock(); } PluginScriptLanguage::PluginScriptLanguage(const godot_pluginscript_language_desc *desc) : _desc(*desc) { _resource_loader = Ref<ResourceFormatLoaderPluginScript>(memnew(ResourceFormatLoaderPluginScript(this))); _resource_saver = Ref<ResourceFormatSaverPluginScript>(memnew(ResourceFormatSaverPluginScript(this))); - -// TODO: totally remove _lock attribute if NO_THREADS is set -#ifdef NO_THREADS - _lock = NULL; -#else - _lock = Mutex::create(); -#endif } PluginScriptLanguage::~PluginScriptLanguage() { -#ifndef NO_THREADS - if (_lock) { - memdelete(_lock); - _lock = NULL; - } -#endif } diff --git a/modules/gdnative/pluginscript/pluginscript_language.h b/modules/gdnative/pluginscript/pluginscript_language.h index 037d7a4948..3f0d2b8d3d 100644 --- a/modules/gdnative/pluginscript/pluginscript_language.h +++ b/modules/gdnative/pluginscript/pluginscript_language.h @@ -53,7 +53,7 @@ class PluginScriptLanguage : public ScriptLanguage { const godot_pluginscript_language_desc _desc; godot_pluginscript_language_data *_data; - Mutex *_lock; + Mutex _lock; SelfList<PluginScript>::List _script_list; public: |