diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp index bb9c1c61ec..ea22ea17ef 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp @@ -71,7 +71,6 @@ static std::mutex s_device_map_mutex; #define IPC_MAX_FDS 0x18 #define ES_MAX_COUNT 2 static std::shared_ptr s_fdmap[IPC_MAX_FDS]; -static bool s_es_inuse[ES_MAX_COUNT]; static std::shared_ptr s_es_handles[ES_MAX_COUNT]; using IPCMsgQueue = std::deque; @@ -141,11 +140,8 @@ void Reinit() AddDevice("/dev/fs"); // IOS allows two ES devices at a time - for (u32 j = 0; j < ES_MAX_COUNT; j++) - { - s_es_handles[j] = AddDevice("/dev/es"); - s_es_inuse[j] = false; - } + for (auto& es_device : s_es_handles) + es_device = AddDevice("/dev/es"); AddDevice("/dev/di"); AddDevice("/dev/net/kd/request"); @@ -189,11 +185,6 @@ void Reset(bool hard) dev.reset(); } - for (bool& in_use : s_es_inuse) - { - in_use = false; - } - { std::lock_guard lock(s_device_map_mutex); for (const auto& entry : s_device_map) @@ -329,13 +320,11 @@ void DoState(PointerWrap& p) } } - for (u32 i = 0; i < ES_MAX_COUNT; i++) + for (auto& es_device : s_es_handles) { - p.Do(s_es_inuse[i]); - u32 handleID = s_es_handles[i]->GetDeviceID(); - p.Do(handleID); - - s_es_handles[i] = AccessDeviceByID(handleID); + const u32 handle_id = es_device->GetDeviceID(); + p.Do(handle_id); + es_device = AccessDeviceByID(handle_id); } } else @@ -360,25 +349,19 @@ void DoState(PointerWrap& p) } } - for (u32 i = 0; i < ES_MAX_COUNT; i++) + for (const auto& es_device : s_es_handles) { - p.Do(s_es_inuse[i]); - u32 handleID = s_es_handles[i]->GetDeviceID(); - p.Do(handleID); + const u32 handle_id = es_device->GetDeviceID(); + p.Do(handle_id); } } } static std::shared_ptr GetUnusedESDevice() { - for (u32 es_number = 0; es_number < ES_MAX_COUNT; ++es_number) - { - if (s_es_inuse[es_number]) - continue; - s_es_inuse[es_number] = true; - return s_es_handles[es_number]; - } - return nullptr; + const auto iterator = std::find_if(std::begin(s_es_handles), std::end(s_es_handles), + [](const auto& es_device) { return !es_device->IsOpened(); }); + return (iterator != std::end(s_es_handles)) ? *iterator : nullptr; } // Returns the FD for the newly opened device (on success) or an error code. @@ -446,11 +429,6 @@ static IPCCommandResult HandleCommand(const u32 address) switch (command) { case IPC_CMD_CLOSE: - for (u32 j = 0; j < ES_MAX_COUNT; j++) - { - if (s_es_handles[j] == s_fdmap[fd]) - s_es_inuse[j] = false; - } s_fdmap[fd].reset(); return device->Close(address); case IPC_CMD_READ: diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 183ef9ff81..3d4a9b3744 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent; static std::thread g_save_thread; // Don't forget to increase this after doing changes on the savestate system -static const u32 STATE_VERSION = 65; // Last changed in PR 4120 +static const u32 STATE_VERSION = 66; // Last changed in PR 4607 // Maps savestate versions to Dolphin versions. // Versions after 42 don't need to be added to this list,