mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-11-25 18:46:55 +01:00
Refactor legacy method of emulating thread events
This commit is contained in:
parent
da8fd5b7c7
commit
f576269ed0
@ -1608,21 +1608,3 @@ namespace coreinit
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void coreinit_suspendThread(OSThread_t* OSThreadBE, sint32 count)
|
||||
{
|
||||
// for legacy source
|
||||
OSThreadBE->suspendCounter += count;
|
||||
}
|
||||
|
||||
void coreinit_resumeThread(OSThread_t* OSThreadBE, sint32 count)
|
||||
{
|
||||
__OSLockScheduler();
|
||||
coreinit::__OSResumeThreadInternal(OSThreadBE, count);
|
||||
__OSUnlockScheduler();
|
||||
}
|
||||
|
||||
OSThread_t* coreinitThread_getCurrentThreadDepr(PPCInterpreter_t* hCPU)
|
||||
{
|
||||
return coreinit::__currentCoreThread[PPCInterpreter_getCoreIndex(hCPU)];
|
||||
}
|
||||
|
@ -621,11 +621,6 @@ namespace coreinit
|
||||
#pragma pack()
|
||||
|
||||
// deprecated / clean up required
|
||||
void coreinit_suspendThread(OSThread_t* OSThreadBE, sint32 count = 1);
|
||||
void coreinit_resumeThread(OSThread_t* OSThreadBE, sint32 count = 1);
|
||||
|
||||
OSThread_t* coreinitThread_getCurrentThreadDepr(PPCInterpreter_t* hCPU);
|
||||
|
||||
extern MPTR activeThread[256];
|
||||
extern sint32 activeThreadCount;
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace nn
|
||||
static_assert(offsetof(nnIdbeEncryptedIcon_t, iconData) == 0x22, "");
|
||||
static_assert(sizeof(nnIdbeEncryptedIcon_t) == 0x12082);
|
||||
|
||||
void asyncDownloadIconFile(uint64 titleId, nnIdbeEncryptedIcon_t* iconOut, OSThread_t* thread)
|
||||
void asyncDownloadIconFile(uint64 titleId, nnIdbeEncryptedIcon_t* iconOut, coreinit::OSEvent* event)
|
||||
{
|
||||
std::vector<uint8> idbeData = NAPI::IDBE_RequestRawEncrypted(ActiveSettings::GetNetworkService(), titleId);
|
||||
if (idbeData.size() != sizeof(nnIdbeEncryptedIcon_t))
|
||||
@ -48,11 +48,11 @@ namespace nn
|
||||
// icon does not exist or has the wrong size
|
||||
cemuLog_log(LogType::Force, "IDBE: Failed to retrieve icon for title {:016x}", titleId);
|
||||
memset(iconOut, 0, sizeof(nnIdbeEncryptedIcon_t));
|
||||
coreinit_resumeThread(thread);
|
||||
coreinit::OSSignalEvent(event);
|
||||
return;
|
||||
}
|
||||
memcpy(iconOut, idbeData.data(), sizeof(nnIdbeEncryptedIcon_t));
|
||||
coreinit_resumeThread(thread);
|
||||
coreinit::OSSignalEvent(event);
|
||||
}
|
||||
|
||||
void export_DownloadIconFile(PPCInterpreter_t* hCPU)
|
||||
@ -62,9 +62,10 @@ namespace nn
|
||||
ppcDefineParamU32(uknR7, 4);
|
||||
ppcDefineParamU32(uknR8, 5);
|
||||
|
||||
auto asyncTask = std::async(std::launch::async, asyncDownloadIconFile, titleId, encryptedIconData, coreinit::OSGetCurrentThread());
|
||||
coreinit::OSSuspendThread(coreinit::OSGetCurrentThread());
|
||||
PPCCore_switchToScheduler();
|
||||
StackAllocator<coreinit::OSEvent> event;
|
||||
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||
auto asyncTask = std::async(std::launch::async, asyncDownloadIconFile, titleId, encryptedIconData, &event);
|
||||
coreinit::OSWaitEvent(&event);
|
||||
osLib_returnFromFunction(hCPU, 1);
|
||||
}
|
||||
|
||||
|
@ -429,8 +429,7 @@ namespace nsyshid
|
||||
|
||||
// handler for synchronous HIDSetReport transfers
|
||||
sint32 _hidSetReportSync(std::shared_ptr<Device> device, uint8* reportData, sint32 length,
|
||||
uint8* originalData,
|
||||
sint32 originalLength, OSThread_t* osThread)
|
||||
uint8* originalData, sint32 originalLength, coreinit::OSEvent* event)
|
||||
{
|
||||
_debugPrintHex("_hidSetReportSync Begin", reportData, length);
|
||||
sint32 returnCode = 0;
|
||||
@ -440,7 +439,7 @@ namespace nsyshid
|
||||
}
|
||||
free(reportData);
|
||||
cemuLog_logDebug(LogType::Force, "_hidSetReportSync end. returnCode: {}", returnCode);
|
||||
coreinit_resumeThread(osThread, 1000);
|
||||
coreinit::OSSignalEvent(event);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
@ -484,11 +483,12 @@ namespace nsyshid
|
||||
sint32 returnCode = 0;
|
||||
if (callbackFuncMPTR == MPTR_NULL)
|
||||
{
|
||||
// synchronous
|
||||
StackAllocator<coreinit::OSEvent> event;
|
||||
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||
std::future<sint32> res = std::async(std::launch::async, &_hidSetReportSync, device, reportData,
|
||||
paddedLength + 1, data, dataLength,
|
||||
coreinitThread_getCurrentThreadDepr(hCPU));
|
||||
coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(hCPU), 1000);
|
||||
PPCCore_switchToScheduler();
|
||||
paddedLength + 1, data, dataLength, &event);
|
||||
coreinit::OSWaitEvent(&event);
|
||||
returnCode = res.get();
|
||||
}
|
||||
else
|
||||
@ -557,10 +557,10 @@ namespace nsyshid
|
||||
sint32 _hidReadSync(std::shared_ptr<Device> device,
|
||||
uint8* data,
|
||||
sint32 maxLength,
|
||||
OSThread_t* osThread)
|
||||
coreinit::OSEvent* event)
|
||||
{
|
||||
sint32 returnCode = _hidReadInternalSync(device, data, maxLength);
|
||||
coreinit_resumeThread(osThread, 1000);
|
||||
coreinit::OSSignalEvent(event);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
@ -591,10 +591,10 @@ namespace nsyshid
|
||||
else
|
||||
{
|
||||
// synchronous transfer
|
||||
std::future<sint32> res = std::async(std::launch::async, &_hidReadSync, device, data, maxLength,
|
||||
coreinitThread_getCurrentThreadDepr(hCPU));
|
||||
coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(hCPU), 1000);
|
||||
PPCCore_switchToScheduler();
|
||||
StackAllocator<coreinit::OSEvent> event;
|
||||
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||
std::future<sint32> res = std::async(std::launch::async, &_hidReadSync, device, data, maxLength, &event);
|
||||
coreinit::OSWaitEvent(&event);
|
||||
returnCode = res.get();
|
||||
}
|
||||
|
||||
@ -654,10 +654,10 @@ namespace nsyshid
|
||||
sint32 _hidWriteSync(std::shared_ptr<Device> device,
|
||||
uint8* data,
|
||||
sint32 maxLength,
|
||||
OSThread_t* osThread)
|
||||
coreinit::OSEvent* event)
|
||||
{
|
||||
sint32 returnCode = _hidWriteInternalSync(device, data, maxLength);
|
||||
coreinit_resumeThread(osThread, 1000);
|
||||
coreinit::OSSignalEvent(event);
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
@ -688,10 +688,10 @@ namespace nsyshid
|
||||
else
|
||||
{
|
||||
// synchronous transfer
|
||||
std::future<sint32> res = std::async(std::launch::async, &_hidWriteSync, device, data, maxLength,
|
||||
coreinitThread_getCurrentThreadDepr(hCPU));
|
||||
coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(hCPU), 1000);
|
||||
PPCCore_switchToScheduler();
|
||||
StackAllocator<coreinit::OSEvent> event;
|
||||
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||
std::future<sint32> res = std::async(std::launch::async, &_hidWriteSync, device, data, maxLength, &event);
|
||||
coreinit::OSWaitEvent(&event);
|
||||
returnCode = res.get();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user