summaryrefslogtreecommitdiffstats
path: root/core/io/resource_loader.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-02-28 00:26:01 +0100
committerGitHub <noreply@github.com>2020-02-28 00:26:01 +0100
commitb7b39786840a41a057f531ed13b64e26366befac (patch)
treeb78a2e0bc0b3f49e82e148e8edb741930ff0ce55 /core/io/resource_loader.cpp
parente66d519286693a03bf59eaba0a5f29c1c9b15d64 (diff)
parent18fbdbb456c07a56b358bea2e392765fbcbb3283 (diff)
downloadredot-engine-b7b39786840a41a057f531ed13b64e26366befac.tar.gz
Merge pull request #36556 from RandomShaper/rework_mutex
Reimplement `Mutex` with C++'s `<mutex>` (plus more)
Diffstat (limited to 'core/io/resource_loader.cpp')
-rw-r--r--core/io/resource_loader.cpp31
1 files changed, 4 insertions, 27 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index 39bbebefa6..b43cd7f1a2 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -288,9 +288,7 @@ RES ResourceLoader::_load(const String &p_path, const String &p_original_path, c
bool ResourceLoader::_add_to_loading_map(const String &p_path) {
bool success;
- if (loading_map_mutex) {
- loading_map_mutex->lock();
- }
+ MutexLock lock(loading_map_mutex);
LoadingMapKey key;
key.path = p_path;
@@ -303,43 +301,27 @@ bool ResourceLoader::_add_to_loading_map(const String &p_path) {
success = true;
}
- if (loading_map_mutex) {
- loading_map_mutex->unlock();
- }
-
return success;
}
void ResourceLoader::_remove_from_loading_map(const String &p_path) {
- if (loading_map_mutex) {
- loading_map_mutex->lock();
- }
+ MutexLock lock(loading_map_mutex);
LoadingMapKey key;
key.path = p_path;
key.thread = Thread::get_caller_id();
loading_map.erase(key);
-
- if (loading_map_mutex) {
- loading_map_mutex->unlock();
- }
}
void ResourceLoader::_remove_from_loading_map_and_thread(const String &p_path, Thread::ID p_thread) {
- if (loading_map_mutex) {
- loading_map_mutex->lock();
- }
+ MutexLock lock(loading_map_mutex);
LoadingMapKey key;
key.path = p_path;
key.thread = p_thread;
loading_map.erase(key);
-
- if (loading_map_mutex) {
- loading_map_mutex->unlock();
- }
}
RES ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache, Error *r_error) {
@@ -1002,13 +984,10 @@ void ResourceLoader::remove_custom_loaders() {
}
}
-Mutex *ResourceLoader::loading_map_mutex = NULL;
+Mutex ResourceLoader::loading_map_mutex;
HashMap<ResourceLoader::LoadingMapKey, int, ResourceLoader::LoadingMapKeyHasher> ResourceLoader::loading_map;
void ResourceLoader::initialize() {
-#ifndef NO_THREADS
- loading_map_mutex = Mutex::create();
-#endif
}
void ResourceLoader::finalize() {
@@ -1018,8 +997,6 @@ void ResourceLoader::finalize() {
ERR_PRINT("Exited while resource is being loaded: " + K->path);
}
loading_map.clear();
- memdelete(loading_map_mutex);
- loading_map_mutex = NULL;
#endif
}