From 36c4dda4ede7e9a79350046d654af1afa758aad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Wed, 11 Jan 2017 14:47:02 +0100 Subject: [PATCH] IOS HLE: Simplify Reset() and SetDefaultContentFile() Reset(): We only need to close IOS devices which were opened, and we can do that simply by iterating over s_fdmap and closing any opened device. With this change, s_device_map can be cleared at once. SetDefaultContentFile(): We can just use s_es_handles which is guaranteed to contain three valid ES devices. Gets rid of a downcast. --- Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp | 40 +++++++----------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp index d9450ea580..1167294875 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp @@ -67,7 +67,7 @@ static std::mutex s_device_map_mutex; constexpr u8 IPC_MAX_FDS = 0x18; constexpr u8 ES_MAX_COUNT = 3; static std::shared_ptr s_fdmap[IPC_MAX_FDS]; -static std::shared_ptr s_es_handles[ES_MAX_COUNT]; +static std::shared_ptr s_es_handles[ES_MAX_COUNT]; using IPCMsgQueue = std::deque; static IPCMsgQueue s_request_queue; // ppc -> arm @@ -171,30 +171,19 @@ void Reset(bool hard) { CoreTiming::RemoveAllEvents(s_event_enqueue); - for (auto& dev : s_fdmap) + // Close all devices that were opened and delete their resources + for (auto& device : s_fdmap) { - if (dev && dev->GetDeviceType() != IWII_IPC_HLE_Device::DeviceType::Static) - { - // close all files and delete their resources - dev->Close(0, true); - } - - dev.reset(); + if (!device) + continue; + device->Close(0, true); + device.reset(); } + if (hard) { std::lock_guard lock(s_device_map_mutex); - for (const auto& entry : s_device_map) - { - if (entry.second) - { - // Force close - entry.second->Close(0, true); - } - } - - if (hard) - s_device_map.clear(); + s_device_map.clear(); } s_request_queue.clear(); @@ -211,13 +200,8 @@ void Shutdown() void SetDefaultContentFile(const std::string& file_name) { std::lock_guard lock(s_device_map_mutex); - for (const auto& entry : s_device_map) - { - if (entry.second && entry.second->GetDeviceName().find("/dev/es") == 0) - { - static_cast(entry.second.get())->LoadWAD(file_name); - } - } + for (const auto& es : s_es_handles) + es->LoadWAD(file_name); } void ES_DIVerify(const std::vector& tmd) @@ -319,7 +303,7 @@ void DoState(PointerWrap& p) { const u32 handle_id = es_device->GetDeviceID(); p.Do(handle_id); - es_device = AccessDeviceByID(handle_id); + es_device = std::static_pointer_cast(AccessDeviceByID(handle_id)); } } else