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

@ -400,39 +400,15 @@ 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
}