mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-05 14:31:17 +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
|
@ -8,27 +8,27 @@ struct CoreinitAsyncCallback
|
|||
|
||||
static void queue(MPTR functionMPTR, uint32 numParameters, uint32 r3, uint32 r4, uint32 r5, uint32 r6, uint32 r7, uint32 r8, uint32 r9, uint32 r10)
|
||||
{
|
||||
s_asyncCallbackSpinlock.acquire();
|
||||
s_asyncCallbackSpinlock.lock();
|
||||
s_asyncCallbackQueue.emplace_back(allocateAndInitFromPool(functionMPTR, numParameters, r3, r4, r5, r6, r7, r8, r9, r10));
|
||||
s_asyncCallbackSpinlock.release();
|
||||
s_asyncCallbackSpinlock.unlock();
|
||||
}
|
||||
|
||||
static void callNextFromQueue()
|
||||
{
|
||||
s_asyncCallbackSpinlock.acquire();
|
||||
s_asyncCallbackSpinlock.lock();
|
||||
if (s_asyncCallbackQueue.empty())
|
||||
{
|
||||
cemuLog_log(LogType::Force, "AsyncCallbackQueue is empty. Unexpected behavior");
|
||||
s_asyncCallbackSpinlock.release();
|
||||
s_asyncCallbackSpinlock.unlock();
|
||||
return;
|
||||
}
|
||||
CoreinitAsyncCallback* cb = s_asyncCallbackQueue[0];
|
||||
s_asyncCallbackQueue.erase(s_asyncCallbackQueue.begin());
|
||||
s_asyncCallbackSpinlock.release();
|
||||
s_asyncCallbackSpinlock.unlock();
|
||||
cb->doCall();
|
||||
s_asyncCallbackSpinlock.acquire();
|
||||
s_asyncCallbackSpinlock.lock();
|
||||
releaseToPool(cb);
|
||||
s_asyncCallbackSpinlock.release();
|
||||
s_asyncCallbackSpinlock.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -39,7 +39,7 @@ private:
|
|||
|
||||
static CoreinitAsyncCallback* allocateAndInitFromPool(MPTR functionMPTR, uint32 numParameters, uint32 r3, uint32 r4, uint32 r5, uint32 r6, uint32 r7, uint32 r8, uint32 r9, uint32 r10)
|
||||
{
|
||||
cemu_assert_debug(s_asyncCallbackSpinlock.isHolding());
|
||||
cemu_assert_debug(s_asyncCallbackSpinlock.is_locked());
|
||||
if (s_asyncCallbackPool.empty())
|
||||
{
|
||||
CoreinitAsyncCallback* cb = new CoreinitAsyncCallback(functionMPTR, numParameters, r3, r4, r5, r6, r7, r8, r9, r10);
|
||||
|
@ -54,7 +54,7 @@ private:
|
|||
|
||||
static void releaseToPool(CoreinitAsyncCallback* cb)
|
||||
{
|
||||
cemu_assert_debug(s_asyncCallbackSpinlock.isHolding());
|
||||
cemu_assert_debug(s_asyncCallbackSpinlock.is_locked());
|
||||
s_asyncCallbackPool.emplace_back(cb);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
// titles that utilize MP task queue: Yoshi's Woolly World, Fast Racing Neo, Tokyo Mirage Sessions, Mii Maker
|
||||
|
||||
#define AcquireMPQLock() s_workaroundSpinlock.acquire()
|
||||
#define ReleaseMPQLock() s_workaroundSpinlock.release()
|
||||
#define AcquireMPQLock() s_workaroundSpinlock.lock()
|
||||
#define ReleaseMPQLock() s_workaroundSpinlock.unlock()
|
||||
|
||||
namespace coreinit
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ namespace coreinit
|
|||
|
||||
void MPInitTask(MPTask* task, void* func, void* data, uint32 size)
|
||||
{
|
||||
s_workaroundSpinlock.acquire();
|
||||
s_workaroundSpinlock.lock();
|
||||
task->thisptr = task;
|
||||
|
||||
task->coreIndex = PPC_CORE_COUNT;
|
||||
|
@ -48,7 +48,7 @@ namespace coreinit
|
|||
|
||||
task->userdata = nullptr;
|
||||
task->runtime = 0;
|
||||
s_workaroundSpinlock.release();
|
||||
s_workaroundSpinlock.unlock();
|
||||
}
|
||||
|
||||
bool MPTermTask(MPTask* task)
|
||||
|
|
|
@ -465,12 +465,12 @@ namespace coreinit
|
|||
|
||||
void _OSFastMutex_AcquireContention(OSFastMutex* fastMutex)
|
||||
{
|
||||
g_fastMutexSpinlock.acquire();
|
||||
g_fastMutexSpinlock.lock();
|
||||
}
|
||||
|
||||
void _OSFastMutex_ReleaseContention(OSFastMutex* fastMutex)
|
||||
{
|
||||
g_fastMutexSpinlock.release();
|
||||
g_fastMutexSpinlock.unlock();
|
||||
}
|
||||
|
||||
void OSFastMutex_LockInternal(OSFastMutex* fastMutex)
|
||||
|
|
|
@ -778,7 +778,7 @@ namespace snd_core
|
|||
|
||||
void AXIst_SyncVPB(AXVPBInternal_t** lastProcessedDSPShadowCopy, AXVPBInternal_t** lastProcessedPPCShadowCopy)
|
||||
{
|
||||
__AXVoiceListSpinlock.acquire();
|
||||
__AXVoiceListSpinlock.lock();
|
||||
|
||||
AXVPBInternal_t* previousInternalDSP = nullptr;
|
||||
AXVPBInternal_t* previousInternalPPC = nullptr;
|
||||
|
@ -869,7 +869,7 @@ namespace snd_core
|
|||
else
|
||||
*lastProcessedPPCShadowCopy = nullptr;
|
||||
}
|
||||
__AXVoiceListSpinlock.release();
|
||||
__AXVoiceListSpinlock.unlock();
|
||||
}
|
||||
|
||||
void AXIst_HandleFrameCallbacks()
|
||||
|
|
|
@ -393,7 +393,7 @@ namespace snd_core
|
|||
AXVPB* AXAcquireVoiceEx(uint32 priority, MPTR callbackEx, MPTR userParam)
|
||||
{
|
||||
cemu_assert(priority != AX_PRIORITY_FREE && priority < AX_PRIORITY_MAX);
|
||||
__AXVoiceListSpinlock.acquire();
|
||||
__AXVoiceListSpinlock.lock();
|
||||
AXVPB* vpb = AXVoiceList_GetFreeVoice();
|
||||
if (vpb != nullptr)
|
||||
{
|
||||
|
@ -410,7 +410,7 @@ namespace snd_core
|
|||
if (droppedVoice == nullptr)
|
||||
{
|
||||
// no voice available
|
||||
__AXVoiceListSpinlock.release();
|
||||
__AXVoiceListSpinlock.unlock();
|
||||
return nullptr;
|
||||
}
|
||||
vpb->userParam = userParam;
|
||||
|
@ -418,18 +418,18 @@ namespace snd_core
|
|||
vpb->callbackEx = callbackEx;
|
||||
AXVPB_SetVoiceDefault(vpb);
|
||||
}
|
||||
__AXVoiceListSpinlock.release();
|
||||
__AXVoiceListSpinlock.unlock();
|
||||
return vpb;
|
||||
}
|
||||
|
||||
void AXFreeVoice(AXVPB* vpb)
|
||||
{
|
||||
cemu_assert(vpb != nullptr);
|
||||
__AXVoiceListSpinlock.acquire();
|
||||
__AXVoiceListSpinlock.lock();
|
||||
if (vpb->priority == (uint32be)AX_PRIORITY_FREE)
|
||||
{
|
||||
forceLog_printf("AXFreeVoice() called on free voice\n");
|
||||
__AXVoiceListSpinlock.release();
|
||||
__AXVoiceListSpinlock.unlock();
|
||||
return;
|
||||
}
|
||||
AXVoiceProtection_Release(vpb);
|
||||
|
@ -442,7 +442,7 @@ namespace snd_core
|
|||
vpb->callback = MPTR_NULL;
|
||||
vpb->callbackEx = MPTR_NULL;
|
||||
AXVoiceList_AddFreeVoice(vpb);
|
||||
__AXVoiceListSpinlock.release();
|
||||
__AXVoiceListSpinlock.unlock();
|
||||
}
|
||||
|
||||
void AXVPBInit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue