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.
This commit is contained in:
Léo Lam 2016-12-05 22:31:51 +01:00
parent b65ad538ba
commit 9abfa54c9d
2 changed files with 13 additions and 35 deletions

View file

@ -71,7 +71,6 @@ static std::mutex s_device_map_mutex;
#define IPC_MAX_FDS 0x18 #define IPC_MAX_FDS 0x18
#define ES_MAX_COUNT 2 #define ES_MAX_COUNT 2
static std::shared_ptr<IWII_IPC_HLE_Device> s_fdmap[IPC_MAX_FDS]; 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]; static std::shared_ptr<IWII_IPC_HLE_Device> s_es_handles[ES_MAX_COUNT];
using IPCMsgQueue = std::deque<u32>; using IPCMsgQueue = std::deque<u32>;
@ -141,11 +140,8 @@ void Reinit()
AddDevice<CWII_IPC_HLE_Device_fs>("/dev/fs"); AddDevice<CWII_IPC_HLE_Device_fs>("/dev/fs");
// IOS allows two ES devices at a time // IOS allows two ES devices at a time
for (u32 j = 0; j < ES_MAX_COUNT; j++) for (auto& es_device : s_es_handles)
{ es_device = AddDevice<CWII_IPC_HLE_Device_es>("/dev/es");
s_es_handles[j] = AddDevice<CWII_IPC_HLE_Device_es>("/dev/es");
s_es_inuse[j] = false;
}
AddDevice<CWII_IPC_HLE_Device_di>("/dev/di"); AddDevice<CWII_IPC_HLE_Device_di>("/dev/di");
AddDevice<CWII_IPC_HLE_Device_net_kd_request>("/dev/net/kd/request"); AddDevice<CWII_IPC_HLE_Device_net_kd_request>("/dev/net/kd/request");
@ -189,11 +185,6 @@ void Reset(bool hard)
dev.reset(); dev.reset();
} }
for (bool& in_use : s_es_inuse)
{
in_use = false;
}
{ {
std::lock_guard<std::mutex> lock(s_device_map_mutex); std::lock_guard<std::mutex> lock(s_device_map_mutex);
for (const auto& entry : s_device_map) 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]); const u32 handle_id = es_device->GetDeviceID();
u32 handleID = s_es_handles[i]->GetDeviceID(); p.Do(handle_id);
p.Do(handleID); es_device = AccessDeviceByID(handle_id);
s_es_handles[i] = AccessDeviceByID(handleID);
} }
} }
else 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]); const u32 handle_id = es_device->GetDeviceID();
u32 handleID = s_es_handles[i]->GetDeviceID(); p.Do(handle_id);
p.Do(handleID);
} }
} }
} }
static std::shared_ptr<IWII_IPC_HLE_Device> GetUnusedESDevice() static std::shared_ptr<IWII_IPC_HLE_Device> GetUnusedESDevice()
{ {
for (u32 es_number = 0; es_number < ES_MAX_COUNT; ++es_number) const auto iterator = std::find_if(std::begin(s_es_handles), std::end(s_es_handles),
{ [](const auto& es_device) { return !es_device->IsOpened(); });
if (s_es_inuse[es_number]) return (iterator != std::end(s_es_handles)) ? *iterator : nullptr;
continue;
s_es_inuse[es_number] = true;
return s_es_handles[es_number];
}
return nullptr;
} }
// Returns the FD for the newly opened device (on success) or an error code. // 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) switch (command)
{ {
case IPC_CMD_CLOSE: 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(); s_fdmap[fd].reset();
return device->Close(address); return device->Close(address);
case IPC_CMD_READ: case IPC_CMD_READ:

View file

@ -71,7 +71,7 @@ static Common::Event g_compressAndDumpStateSyncEvent;
static std::thread g_save_thread; static std::thread g_save_thread;
// Don't forget to increase this after doing changes on the savestate system // 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. // Maps savestate versions to Dolphin versions.
// Versions after 42 don't need to be added to this list, // Versions after 42 don't need to be added to this list,