diff options
author | reduz <reduzio@gmail.com> | 2022-06-22 13:46:46 +0200 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2022-06-22 13:46:46 +0200 |
commit | e772b65d92dbd5b36fb003458d7fe0fd528abcea (patch) | |
tree | aca74602fef05e8f80689345af9ba2e33afe846d /scene | |
parent | c18d0f20357a11bd9cfa2f57b8b9b500763413bc (diff) |
Remake resource thread safety and API
* Ensures thread safety when resources are destroyed.
* Simplified API by always forcing `ResourceCache::get_ref`, which needs less hacks and is fully thread safe.
* Removed RWLock for resources because its not possible to use for the new logic. Should not be a problem.
Supersedes #57533
Diffstat (limited to 'scene')
-rw-r--r-- | scene/debugger/scene_debugger.cpp | 4 | ||||
-rw-r--r-- | scene/resources/resource_format_text.cpp | 22 |
2 files changed, 12 insertions, 14 deletions
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index a54e728c1b..e9c33b1839 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -701,7 +701,7 @@ void LiveEditor::_res_set_func(int p_id, const StringName &p_prop, const Variant return; } - Ref<Resource> r = ResourceCache::get(resp); + Ref<Resource> r = ResourceCache::get_ref(resp); if (!r.is_valid()) { return; } @@ -728,7 +728,7 @@ void LiveEditor::_res_call_func(int p_id, const StringName &p_method, const Vari return; } - Ref<Resource> r = ResourceCache::get(resp); + Ref<Resource> r = ResourceCache::get_ref(resp); if (!r.is_valid()) { return; } diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 0320585b5a..5080517707 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -528,9 +528,9 @@ Error ResourceLoaderText::load() { if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(path)) { //reuse existing - Resource *r = ResourceCache::get(path); - if (r && r->get_class() == type) { - res = Ref<Resource>(r); + Ref<Resource> cache = ResourceCache::get_ref(path); + if (cache.is_valid() && cache->get_class() == type) { + res = cache; res->reset_state(); do_assign = true; } @@ -539,10 +539,10 @@ Error ResourceLoaderText::load() { MissingResource *missing_resource = nullptr; if (res.is_null()) { //not reuse - if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && ResourceCache::has(path)) { //only if it doesn't exist + Ref<Resource> cache = ResourceCache::get_ref(path); + if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE && cache.is_valid()) { //only if it doesn't exist //cached, do not assign - Resource *r = ResourceCache::get(path); - res = Ref<Resource>(r); + res = cache; } else { //create @@ -652,12 +652,10 @@ Error ResourceLoaderText::load() { return error; } - if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && ResourceCache::has(local_path)) { - Resource *r = ResourceCache::get(local_path); - if (r->get_class() == res_type) { - r->reset_state(); - resource = Ref<Resource>(r); - } + Ref<Resource> cache = ResourceCache::get_ref(local_path); + if (cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE && cache.is_valid() && cache->get_class() == res_type) { + cache->reset_state(); + resource = cache; } MissingResource *missing_resource = nullptr; |