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:
Pedro J. Estébanez 2021-01-27 10:43:02 +01:00
parent b450036120
commit 4ddcdc031b
99 changed files with 472 additions and 1391 deletions

View file

@ -1279,9 +1279,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
gdfs->state.ip = ip + ipofs;
gdfs->state.line = line;
gdfs->state.script = _script;
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->lock();
#endif
GDScriptLanguage::singleton->lock.lock();
_script->pending_func_states.add(&gdfs->scripts_list);
if (p_instance) {
@ -1290,9 +1288,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
} else {
gdfs->state.instance = NULL;
}
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->unlock();
#endif
GDScriptLanguage::singleton->lock.unlock();
#ifdef DEBUG_ENABLED
gdfs->state.function_name = name;
gdfs->state.script_path = _script->get_path();
@ -1776,14 +1772,9 @@ GDScriptFunction::GDScriptFunction() :
#ifdef DEBUG_ENABLED
_func_cname = NULL;
if (GDScriptLanguage::get_singleton()->lock) {
GDScriptLanguage::get_singleton()->lock->lock();
}
GDScriptLanguage::get_singleton()->lock.lock();
GDScriptLanguage::get_singleton()->function_list.add(&function_list);
if (GDScriptLanguage::get_singleton()->lock) {
GDScriptLanguage::get_singleton()->lock->unlock();
}
GDScriptLanguage::get_singleton()->lock.unlock();
profile.call_count = 0;
profile.self_time = 0;
@ -1800,14 +1791,9 @@ GDScriptFunction::GDScriptFunction() :
GDScriptFunction::~GDScriptFunction() {
#ifdef DEBUG_ENABLED
if (GDScriptLanguage::get_singleton()->lock) {
GDScriptLanguage::get_singleton()->lock->lock();
}
GDScriptLanguage::get_singleton()->lock.lock();
GDScriptLanguage::get_singleton()->function_list.remove(&function_list);
if (GDScriptLanguage::get_singleton()->lock) {
GDScriptLanguage::get_singleton()->lock->unlock();
}
GDScriptLanguage::get_singleton()->lock.unlock();
#endif
}
@ -1958,12 +1944,8 @@ GDScriptFunctionState::GDScriptFunctionState() :
GDScriptFunctionState::~GDScriptFunctionState() {
_clear_stack();
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->lock();
#endif
GDScriptLanguage::singleton->lock.lock();
scripts_list.remove_from_list();
instances_list.remove_from_list();
#ifndef NO_THREADS
GDScriptLanguage::singleton->lock->unlock();
#endif
GDScriptLanguage::singleton->lock.unlock();
}