diff options
| author | Léo Lam <leo@innovatetechnologi.es> | 2016-12-05 22:31:51 +0100 |
|---|---|---|
| committer | Léo Lam <leo@innovatetechnologi.es> | 2017-01-05 01:04:19 +0100 |
| commit | 9abfa54c9dae0ddd2979413504ae567955be1354 (patch) | |
| tree | 3c6c1ce6d63ae999e7d526e6432a6a1ae42a68f4 /Source/Core | |
| parent | b65ad538bab6d56bda2a0e6dbea785c0cb291f43 (diff) | |
IOS HLE: Remove s_es_inuse
We don't really have to keep track of device opens/closes manually,
since we can already check that by calling IsOpened() on the device.
This also replaces some loops with for range loops.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/IPC_HLE/WII_IPC_HLE.cpp | 46 | ||||
| -rw-r--r-- | Source/Core/Core/State.cpp | 2 |
2 files changed, 13 insertions, 35 deletions
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<IWII_IPC_HLE_Device> s_fdmap[IPC_MAX_FDS]; -static bool s_es_inuse[ES_MAX_COUNT]; static std::shared_ptr<IWII_IPC_HLE_Device> s_es_handles[ES_MAX_COUNT]; using IPCMsgQueue = std::deque<u32>; @@ -141,11 +140,8 @@ void Reinit() AddDevice<CWII_IPC_HLE_Device_fs>("/dev/fs"); // IOS allows two ES devices at a time - for (u32 j = 0; j < ES_MAX_COUNT; j++) - { - s_es_handles[j] = AddDevice<CWII_IPC_HLE_Device_es>("/dev/es"); - s_es_inuse[j] = false; - } + for (auto& es_device : s_es_handles) + es_device = AddDevice<CWII_IPC_HLE_Device_es>("/dev/es"); AddDevice<CWII_IPC_HLE_Device_di>("/dev/di"); AddDevice<CWII_IPC_HLE_Device_net_kd_request>("/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<std::mutex> 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<IWII_IPC_HLE_Device> 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, |
