1#include "Game/System/FunctionAsyncExecutor.hpp"
2#include <JSystem/JKernel/JKRUnitHeap.hpp>
3#include "Game/Util.hpp"
6FunctionAsyncExecInfo::FunctionAsyncExecInfo(
MR::FunctorBase *pFuncPtr,
int a2,
const char *a3) {
11 OSInitMessageQueue(&mQueue, &mMessage, 1);
14FunctionAsyncExecInfo::~FunctionAsyncExecInfo() {
18void FunctionAsyncExecInfo::execute() {
19 OSThread* thread = OSGetCurrentThread();
20 OSPriority prio = OSGetThreadPriority(thread);
21 OSSetThreadPriority(thread, mPriority);
23 OSSetThreadPriority(thread, prio);
26FunctionAsyncExecutorThread::FunctionAsyncExecutorThread(JKRHeap *pHeap) :
OSThreadWrapper(0x10000, 4, 1, pHeap) {
31s32 FunctionAsyncExecutorThread::run() {
51 OSReceiveMessage(&mQueue, &msg, OS_MESSAGE_BLOCK);
56 OSSendMessage(&info->mQueue, 0, 0);
61FunctionAsyncExecutorOnMainThread::FunctionAsyncExecutorOnMainThread(OSThread* pThread) {
64 OSInitMessageQueue(&mQueue, mMsgArray, 0x40);
67void FunctionAsyncExecutorOnMainThread::update() {
70 if (OSReceiveMessage(&mQueue, &msg, 0)) {
73 info->mPriority = OSGetThreadPriority(OSGetCurrentThread());
75 OSSendMessage(&info->mQueue, 0, 0);
80FunctionAsyncExecutor::FunctionAsyncExecutor() {
81 mMainThreadExec =
nullptr;
86 for (
int i = 0; i < 2; i++) {
89 OSResumeThread(thread->mThread);
93 _410 = JKRUnitHeap::create(0x34, 0x34A8, 4, MR::getCurrentHeap(),
false);
94 _414 = JKRExpHeap::create(0x2800, MR::getCurrentHeap(),
false);
97void FunctionAsyncExecutor::update() {
98 mMainThreadExec->update();
101void FunctionAsyncExecutor::start(
const MR::FunctorBase &rBase,
int priority,
const char *pName) {
104 OSSendMessage(&thread->mQueue, info, 0);
107bool FunctionAsyncExecutor::startOnMainThread(
const MR::FunctorBase &rBase,
const char *pName) {
109 bool isSameThread = OSGetCurrentThread() == thread->mThread;
117 OSSendMessage(&mMainThreadExec->mQueue, info, 0);
122void FunctionAsyncExecutor::waitForEnd(
const char *pName) {
127 while (cur != lst && (*cur)->isSame(pName)) {
133 OSReceiveMessage(&info->mQueue, &info->mMessage, OS_MESSAGE_BLOCK);
138 while (cur != lst && *cur != info) {
142 if (lst - cur - 1 > 0) {
143 while (cur + 1 != last()) {
155bool FunctionAsyncExecutor::isEnd(
const char *pName)
const {
160 while((cur != lst) && (*cur)->isSame(pName)) {
169OSThread* FunctionAsyncExecutor::getOSThread(
const char *pName) {
170 for (
int i = 0; i < 2; i++) {
173 if (thread->mIsSuspended && MR::isEqualString(thread->_40, pName)) {
174 return thread->mThread;
188 mHolders[cnt] = info;
194 for (
int i = 0; i < 2; i++) {
195 if (mThreads[i]->mIsSuspended) {
203FunctionAsyncExecutorThread::~FunctionAsyncExecutorThread() {