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()
|
#pragma pack()
|
||||||
|
|
||||||
// deprecated / clean up required
|
// 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 MPTR activeThread[256];
|
||||||
extern sint32 activeThreadCount;
|
extern sint32 activeThreadCount;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ namespace nn
|
|||||||
static_assert(offsetof(nnIdbeEncryptedIcon_t, iconData) == 0x22, "");
|
static_assert(offsetof(nnIdbeEncryptedIcon_t, iconData) == 0x22, "");
|
||||||
static_assert(sizeof(nnIdbeEncryptedIcon_t) == 0x12082);
|
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);
|
std::vector<uint8> idbeData = NAPI::IDBE_RequestRawEncrypted(ActiveSettings::GetNetworkService(), titleId);
|
||||||
if (idbeData.size() != sizeof(nnIdbeEncryptedIcon_t))
|
if (idbeData.size() != sizeof(nnIdbeEncryptedIcon_t))
|
||||||
@ -48,11 +48,11 @@ namespace nn
|
|||||||
// icon does not exist or has the wrong size
|
// icon does not exist or has the wrong size
|
||||||
cemuLog_log(LogType::Force, "IDBE: Failed to retrieve icon for title {:016x}", titleId);
|
cemuLog_log(LogType::Force, "IDBE: Failed to retrieve icon for title {:016x}", titleId);
|
||||||
memset(iconOut, 0, sizeof(nnIdbeEncryptedIcon_t));
|
memset(iconOut, 0, sizeof(nnIdbeEncryptedIcon_t));
|
||||||
coreinit_resumeThread(thread);
|
coreinit::OSSignalEvent(event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(iconOut, idbeData.data(), sizeof(nnIdbeEncryptedIcon_t));
|
memcpy(iconOut, idbeData.data(), sizeof(nnIdbeEncryptedIcon_t));
|
||||||
coreinit_resumeThread(thread);
|
coreinit::OSSignalEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void export_DownloadIconFile(PPCInterpreter_t* hCPU)
|
void export_DownloadIconFile(PPCInterpreter_t* hCPU)
|
||||||
@ -62,9 +62,10 @@ namespace nn
|
|||||||
ppcDefineParamU32(uknR7, 4);
|
ppcDefineParamU32(uknR7, 4);
|
||||||
ppcDefineParamU32(uknR8, 5);
|
ppcDefineParamU32(uknR8, 5);
|
||||||
|
|
||||||
auto asyncTask = std::async(std::launch::async, asyncDownloadIconFile, titleId, encryptedIconData, coreinit::OSGetCurrentThread());
|
StackAllocator<coreinit::OSEvent> event;
|
||||||
coreinit::OSSuspendThread(coreinit::OSGetCurrentThread());
|
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||||
PPCCore_switchToScheduler();
|
auto asyncTask = std::async(std::launch::async, asyncDownloadIconFile, titleId, encryptedIconData, &event);
|
||||||
|
coreinit::OSWaitEvent(&event);
|
||||||
osLib_returnFromFunction(hCPU, 1);
|
osLib_returnFromFunction(hCPU, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,8 +429,7 @@ namespace nsyshid
|
|||||||
|
|
||||||
// handler for synchronous HIDSetReport transfers
|
// handler for synchronous HIDSetReport transfers
|
||||||
sint32 _hidSetReportSync(std::shared_ptr<Device> device, uint8* reportData, sint32 length,
|
sint32 _hidSetReportSync(std::shared_ptr<Device> device, uint8* reportData, sint32 length,
|
||||||
uint8* originalData,
|
uint8* originalData, sint32 originalLength, coreinit::OSEvent* event)
|
||||||
sint32 originalLength, OSThread_t* osThread)
|
|
||||||
{
|
{
|
||||||
_debugPrintHex("_hidSetReportSync Begin", reportData, length);
|
_debugPrintHex("_hidSetReportSync Begin", reportData, length);
|
||||||
sint32 returnCode = 0;
|
sint32 returnCode = 0;
|
||||||
@ -440,7 +439,7 @@ namespace nsyshid
|
|||||||
}
|
}
|
||||||
free(reportData);
|
free(reportData);
|
||||||
cemuLog_logDebug(LogType::Force, "_hidSetReportSync end. returnCode: {}", returnCode);
|
cemuLog_logDebug(LogType::Force, "_hidSetReportSync end. returnCode: {}", returnCode);
|
||||||
coreinit_resumeThread(osThread, 1000);
|
coreinit::OSSignalEvent(event);
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,11 +483,12 @@ namespace nsyshid
|
|||||||
sint32 returnCode = 0;
|
sint32 returnCode = 0;
|
||||||
if (callbackFuncMPTR == MPTR_NULL)
|
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,
|
std::future<sint32> res = std::async(std::launch::async, &_hidSetReportSync, device, reportData,
|
||||||
paddedLength + 1, data, dataLength,
|
paddedLength + 1, data, dataLength, &event);
|
||||||
coreinitThread_getCurrentThreadDepr(hCPU));
|
coreinit::OSWaitEvent(&event);
|
||||||
coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(hCPU), 1000);
|
|
||||||
PPCCore_switchToScheduler();
|
|
||||||
returnCode = res.get();
|
returnCode = res.get();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -557,10 +557,10 @@ namespace nsyshid
|
|||||||
sint32 _hidReadSync(std::shared_ptr<Device> device,
|
sint32 _hidReadSync(std::shared_ptr<Device> device,
|
||||||
uint8* data,
|
uint8* data,
|
||||||
sint32 maxLength,
|
sint32 maxLength,
|
||||||
OSThread_t* osThread)
|
coreinit::OSEvent* event)
|
||||||
{
|
{
|
||||||
sint32 returnCode = _hidReadInternalSync(device, data, maxLength);
|
sint32 returnCode = _hidReadInternalSync(device, data, maxLength);
|
||||||
coreinit_resumeThread(osThread, 1000);
|
coreinit::OSSignalEvent(event);
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -591,10 +591,10 @@ namespace nsyshid
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// synchronous transfer
|
// synchronous transfer
|
||||||
std::future<sint32> res = std::async(std::launch::async, &_hidReadSync, device, data, maxLength,
|
StackAllocator<coreinit::OSEvent> event;
|
||||||
coreinitThread_getCurrentThreadDepr(hCPU));
|
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||||
coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(hCPU), 1000);
|
std::future<sint32> res = std::async(std::launch::async, &_hidReadSync, device, data, maxLength, &event);
|
||||||
PPCCore_switchToScheduler();
|
coreinit::OSWaitEvent(&event);
|
||||||
returnCode = res.get();
|
returnCode = res.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -654,10 +654,10 @@ namespace nsyshid
|
|||||||
sint32 _hidWriteSync(std::shared_ptr<Device> device,
|
sint32 _hidWriteSync(std::shared_ptr<Device> device,
|
||||||
uint8* data,
|
uint8* data,
|
||||||
sint32 maxLength,
|
sint32 maxLength,
|
||||||
OSThread_t* osThread)
|
coreinit::OSEvent* event)
|
||||||
{
|
{
|
||||||
sint32 returnCode = _hidWriteInternalSync(device, data, maxLength);
|
sint32 returnCode = _hidWriteInternalSync(device, data, maxLength);
|
||||||
coreinit_resumeThread(osThread, 1000);
|
coreinit::OSSignalEvent(event);
|
||||||
return returnCode;
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,10 +688,10 @@ namespace nsyshid
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// synchronous transfer
|
// synchronous transfer
|
||||||
std::future<sint32> res = std::async(std::launch::async, &_hidWriteSync, device, data, maxLength,
|
StackAllocator<coreinit::OSEvent> event;
|
||||||
coreinitThread_getCurrentThreadDepr(hCPU));
|
coreinit::OSInitEvent(&event, coreinit::OSEvent::EVENT_STATE::STATE_NOT_SIGNALED, coreinit::OSEvent::EVENT_MODE::MODE_AUTO);
|
||||||
coreinit_suspendThread(coreinitThread_getCurrentThreadDepr(hCPU), 1000);
|
std::future<sint32> res = std::async(std::launch::async, &_hidWriteSync, device, data, maxLength, &event);
|
||||||
PPCCore_switchToScheduler();
|
coreinit::OSWaitEvent(&event);
|
||||||
returnCode = res.get();
|
returnCode = res.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user