Merge pull request #94910 from RandomShaper/res_load_unlocked

ResourceLoader: Let resource setup late steps invoke loading in turn
This commit is contained in:
Rémi Verschelde 2024-07-31 11:37:41 +02:00
commit 372b3f8437
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -345,7 +345,14 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
bool ignoring = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP; bool ignoring = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP;
bool replacing = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP; bool replacing = load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || load_task.cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP;
bool unlock_pending = true;
if (load_task.resource.is_valid()) { if (load_task.resource.is_valid()) {
// From now on, no critical section needed as no one will write to the task anymore.
// Moreover, the mutex being unlocked is a requirement if some of the calls below
// that set the resource up invoke code that in turn requests resource loading.
thread_load_mutex.unlock();
unlock_pending = false;
if (!ignoring) { if (!ignoring) {
if (replacing) { if (replacing) {
Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path); Ref<Resource> old_res = ResourceCache::get_ref(load_task.local_path);
@ -383,13 +390,18 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
load_task.status = THREAD_LOAD_LOADED; load_task.status = THREAD_LOAD_LOADED;
load_task.progress = 1.0; load_task.progress = 1.0;
thread_load_mutex.unlock();
unlock_pending = false;
if (_loaded_callback) { if (_loaded_callback) {
_loaded_callback(load_task.resource, load_task.local_path); _loaded_callback(load_task.resource, load_task.local_path);
} }
} }
} }
thread_load_mutex.unlock(); if (unlock_pending) {
thread_load_mutex.unlock();
}
if (load_nesting == 0) { if (load_nesting == 0) {
if (own_mq_override) { if (own_mq_override) {