You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Modernize Mutex
- Based on C++11's `mutex` - No more need to allocate-deallocate or check for null - No pointer anymore, just a member variable - Platform-specific implementations no longer needed - Simpler for `NO_THREADS` - `BinaryMutex` added for special cases as the non-recursive version - `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`. - `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same.
This commit is contained in:
@@ -220,15 +220,9 @@ 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
|
||||
|
||||
owners_lock.lock();
|
||||
instance_owners.insert(p_this);
|
||||
|
||||
#ifndef NO_THREADS
|
||||
owners_lock->unlock();
|
||||
#endif
|
||||
owners_lock.unlock();
|
||||
|
||||
return nsi;
|
||||
}
|
||||
@@ -524,17 +518,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()
|
||||
@@ -911,15 +898,9 @@ NativeScriptInstance::~NativeScriptInstance() {
|
||||
|
||||
if (owner) {
|
||||
|
||||
#ifndef NO_THREADS
|
||||
script->owners_lock->lock();
|
||||
#endif
|
||||
|
||||
script->owners_lock.lock();
|
||||
script->instance_owners.erase(owner);
|
||||
|
||||
#ifndef NO_THREADS
|
||||
script->owners_lock->unlock();
|
||||
#endif
|
||||
script->owners_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1016,7 +997,6 @@ NativeScriptLanguage::NativeScriptLanguage() {
|
||||
NativeScriptLanguage::singleton = this;
|
||||
#ifndef NO_THREADS
|
||||
has_objects_to_register = false;
|
||||
mutex = Mutex::create();
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
@@ -1053,10 +1033,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 {
|
||||
|
||||
Reference in New Issue
Block a user