Make controller button code thread-safe (#405)

* Refactor spinlock to meet Lockable requirements
* Input: Refactor button code and make it thread-safe
This commit is contained in:
Exzap 2022-10-23 15:47:42 +02:00 committed by GitHub
parent c40466f3a8
commit 028b3f7992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 311 additions and 220 deletions

View file

@ -234,38 +234,38 @@ namespace iosu
void _IPCInitDispatchablePool()
{
sIPCDispatchableCommandPoolLock.acquire();
sIPCDispatchableCommandPoolLock.lock();
while (!sIPCFreeDispatchableCommands.empty())
sIPCFreeDispatchableCommands.pop();
for (size_t i = 0; i < sIPCDispatchableCommandPool.GetCount(); i++)
sIPCFreeDispatchableCommands.push(sIPCDispatchableCommandPool.GetPtr()+i);
sIPCDispatchableCommandPoolLock.release();
sIPCDispatchableCommandPoolLock.unlock();
}
IOSDispatchableCommand* _IPCAllocateDispatchableCommand()
{
sIPCDispatchableCommandPoolLock.acquire();
sIPCDispatchableCommandPoolLock.lock();
if (sIPCFreeDispatchableCommands.empty())
{
cemuLog_log(LogType::Force, "IOS: Exhausted pool of dispatchable commands");
sIPCDispatchableCommandPoolLock.release();
sIPCDispatchableCommandPoolLock.unlock();
return nullptr;
}
IOSDispatchableCommand* cmd = sIPCFreeDispatchableCommands.front();
sIPCFreeDispatchableCommands.pop();
cemu_assert_debug(!cmd->isAllocated);
cmd->isAllocated = true;
sIPCDispatchableCommandPoolLock.release();
sIPCDispatchableCommandPoolLock.unlock();
return cmd;
}
void _IPCReleaseDispatchableCommand(IOSDispatchableCommand* cmd)
{
sIPCDispatchableCommandPoolLock.acquire();
sIPCDispatchableCommandPoolLock.lock();
cemu_assert_debug(cmd->isAllocated);
cmd->isAllocated = false;
sIPCFreeDispatchableCommands.push(cmd);
sIPCDispatchableCommandPoolLock.release();
sIPCDispatchableCommandPoolLock.unlock();
}
static constexpr size_t MAX_NUM_ACTIVE_DEV_HANDLES = 96; // per process