From ee173dc3a21e61771eadc048dc71c5fa725c4814 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 26 Jan 2017 04:03:03 +0300 Subject: [PATCH] IdManager fix --- rpcs3/Emu/Cell/Modules/cellFs.cpp | 32 ++++++++++++++++++++----------- rpcs3/Emu/IdManager.cpp | 29 ++++------------------------ rpcs3/Emu/IdManager.h | 18 ++++++----------- 3 files changed, 31 insertions(+), 48 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/cellFs.cpp b/rpcs3/Emu/Cell/Modules/cellFs.cpp index 5b634204da..0ff30feb53 100644 --- a/rpcs3/Emu/Cell/Modules/cellFs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellFs.cpp @@ -737,12 +737,6 @@ struct fs_aio_thread : ppu_thread struct fs_aio_manager { std::shared_ptr thread; - - fs_aio_manager() - : thread(idm::make_ptr("FS AIO Thread", 500)) - { - thread->run(); - } }; s32 cellFsAioInit(vm::cptr mount_point) @@ -750,7 +744,13 @@ s32 cellFsAioInit(vm::cptr mount_point) cellFs.warning("cellFsAioInit(mount_point=%s)", mount_point); // TODO: create AIO thread (if not exists) for specified mount point - fxm::get_always(); + const auto m = fxm::make(); + + if (m) + { + m->thread = idm::make_ptr("FS AIO Thread", 500); + m->thread->run(); + } return CELL_OK; } @@ -772,9 +772,14 @@ s32 cellFsAioRead(vm::ptr aio, vm::ptr id, fs_aio_cb_t func) // TODO: detect mount point and send AIO request to the AIO thread of this mount point - const s32 xid = (*id = ++g_fs_aio_id); + const auto m = fxm::get(); - const auto m = fxm::get_always(); + if (!m) + { + return CELL_ENXIO; + } + + const s32 xid = (*id = ++g_fs_aio_id); m->thread->cmd_list ({ @@ -793,9 +798,14 @@ s32 cellFsAioWrite(vm::ptr aio, vm::ptr id, fs_aio_cb_t func) // TODO: detect mount point and send AIO request to the AIO thread of this mount point - const s32 xid = (*id = ++g_fs_aio_id); + const auto m = fxm::get(); - const auto m = fxm::get_always(); + if (!m) + { + return CELL_ENXIO; + } + + const s32 xid = (*id = ++g_fs_aio_id); m->thread->cmd_list ({ diff --git a/rpcs3/Emu/IdManager.cpp b/rpcs3/Emu/IdManager.cpp index 138a39273d..06a1e8e015 100644 --- a/rpcs3/Emu/IdManager.cpp +++ b/rpcs3/Emu/IdManager.cpp @@ -64,39 +64,18 @@ id_manager::id_map::pointer idm::allocate_id(std::pair types, u32 base return nullptr; } -id_manager::id_map::pointer idm::find_id(u32 type, u32 id) -{ - auto& map = g_map[type]; - - const auto found = map.find(id); - - return found == map.end() ? nullptr : std::addressof(*found); -} - id_manager::id_map::pointer idm::find_id(u32 type, u32 true_type, u32 id) { auto& map = g_map[type]; const auto found = map.find(id); - return found == map.end() || found->first.type() != true_type ? nullptr : std::addressof(*found); -} - -std::shared_ptr idm::delete_id(u32 type, u32 id) -{ - auto& map = g_map[type]; - - const auto found = map.find(id); - - std::shared_ptr result; - - if (found != map.end()) + if (found != map.end() && (type == true_type || found->first.type() == true_type)) { - result = std::move(found->second); - map.erase(found); + return std::addressof(*found); } - return result; + return nullptr; } std::shared_ptr idm::delete_id(u32 type, u32 true_type, u32 id) @@ -107,7 +86,7 @@ std::shared_ptr idm::delete_id(u32 type, u32 true_type, u32 id) std::shared_ptr result; - if (found != map.end() && found->first.type() == true_type) + if (found != map.end() && (type == true_type || found->first.type() == true_type)) { result = std::move(found->second); map.erase(found); diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index 1901c280f3..e0e109502c 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -232,16 +232,10 @@ class idm // Prepare new ID (returns nullptr if out of resources) static id_manager::id_map::pointer allocate_id(std::pair types, u32 base, u32 step, u32 count); - // Remove ID and return the object - static std::shared_ptr delete_id(u32 type, u32 id); - - // Remove ID and return the object (check type) + // Remove ID and return the object (additionally check true_type if not equal) static std::shared_ptr delete_id(u32 type, u32 true_type, u32 id); - // Get ID - static id_manager::id_map::pointer find_id(u32 type, u32 id); - - // Get ID (check type) + // Get ID (additionally check true_type if not equal) static id_manager::id_map::pointer find_id(u32 type, u32 true_type, u32 id); // Allocate new ID and assign the object from the provider() @@ -267,7 +261,7 @@ class idm } catch (...) { - delete_id(types.first, place->first.id()); + delete_id(types.first, types.first, place->first.id()); throw; } } @@ -488,7 +482,7 @@ public: } // Get count of objects - template + template static inline u32 get_count() { reader_lock lock(id_manager::g_mutex); @@ -558,7 +552,7 @@ public: func(*static_cast(found->second.get())); - ptr = delete_id(get_type(), id); + ptr = delete_id(get_type(), get_type(), id); g_map[get_type()].erase(id); } @@ -595,7 +589,7 @@ public: return result_type{{found->second, _ptr}, std::move(ret)}; } - ptr = delete_id(get_type(), id); + ptr = delete_id(get_type(), get_type(), id); g_map[get_type()].erase(id); }