mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-10 08:51:19 +12:00
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:
parent
c40466f3a8
commit
028b3f7992
28 changed files with 311 additions and 220 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue