1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-13 11:24:40 +00:00

Message Queues, Threads, and surroundings cleanup (#1178)

* message queues, threads, and surroundings cleanup

* Format, make the formatter prefer clang-format-11 if found

* Fix __osThreadTail type

* Q -> Queue, thread defines renamed

* Reformat, add missing NULL

* Suggested changes and further casting cleanup

* Reformat

* padmgr name fixes
This commit is contained in:
Tharo 2022-04-09 01:20:23 +01:00 committed by GitHub
parent 9984c267d9
commit 7068ad3703
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
45 changed files with 311 additions and 296 deletions

View file

@ -82,12 +82,12 @@ void Sched_HandleReset(SchedContext* sc) {
if (sc->curRSPTask != NULL) {
LOG_TIME("(((u64)(now - graph_rsp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
OS_CYCLES_TO_USEC(now - sRSPGFXStartTime), "../sched.c", 427);
osSendMesg(&sc->interruptQ, RSP_DONE_MSG, OS_MESG_NOBLOCK);
osSendMesg(&sc->interruptQueue, (OSMesg)RSP_DONE_MSG, OS_MESG_NOBLOCK);
}
if (sc->curRDPTask != NULL) {
LOG_TIME("(((u64)(now - rdp_start_time)*(1000000LL/15625LL))/((62500000LL*3/4)/15625LL))",
OS_CYCLES_TO_USEC(now - sRDPStartTime), "../sched.c", 431);
osSendMesg(&sc->interruptQ, RDP_DONE_MSG, OS_MESG_NOBLOCK);
osSendMesg(&sc->interruptQueue, (OSMesg)RDP_DONE_MSG, OS_MESG_NOBLOCK);
}
}
}
@ -231,8 +231,8 @@ void func_800C8BC4(SchedContext* sc, OSScTask* task) {
u32 Sched_IsComplete(SchedContext* sc, OSScTask* task) {
if (!(task->state & (OS_SC_DP | OS_SC_SP))) {
if (task->msgQ != NULL) {
osSendMesg(task->msgQ, task->msg, OS_MESG_BLOCK);
if (task->msgQueue != NULL) {
osSendMesg(task->msgQueue, task->msg, OS_MESG_BLOCK);
}
if (task->flags & OS_SC_SWAPBUFFER) {
@ -292,10 +292,10 @@ void Sched_HandleEntry(SchedContext* sc) {
OSScTask* nextRSP = NULL;
OSScTask* nextRDP = NULL;
s32 state;
OSMesg msg = NULL;
OSScTask* task = NULL;
while (osRecvMesg(&sc->cmdQ, &msg, OS_MESG_NOBLOCK) != -1) {
Sched_QueueTask(sc, msg);
while (osRecvMesg(&sc->cmdQueue, (OSMesg*)&task, OS_MESG_NOBLOCK) != -1) {
Sched_QueueTask(sc, task);
}
if (sc->doAudio != 0 && sc->curRSPTask != NULL) {
@ -425,22 +425,20 @@ void Sched_SendEntryMsg(SchedContext* sc) {
osSyncPrintf("osScKickEntryMsg\n");
}
osSendMesg(&sc->interruptQ, ENTRY_MSG, OS_MESG_BLOCK);
osSendMesg(&sc->interruptQueue, (OSMesg)ENTRY_MSG, OS_MESG_BLOCK);
}
void Sched_ThreadEntry(void* arg) {
void* msg;
OSMesg msg = NULL;
SchedContext* sc = (SchedContext*)arg;
msg = NULL;
while (true) {
if (sLogScheduler) {
// "%08d: standby"
osSyncPrintf("%08d:待機中\n", (u32)OS_CYCLES_TO_USEC(osGetTime()));
}
osRecvMesg(&sc->interruptQ, &msg, OS_MESG_BLOCK);
osRecvMesg(&sc->interruptQueue, &msg, OS_MESG_BLOCK);
switch ((s32)msg) {
case ENTRY_MSG:
@ -461,8 +459,6 @@ void Sched_ThreadEntry(void* arg) {
}
Sched_HandleRDPDone(sc);
continue;
default:
break;
}
switch (((OSScMsg*)msg)->type) {
case 1:
@ -481,11 +477,11 @@ void Sched_ThreadEntry(void* arg) {
void Sched_Init(SchedContext* sc, void* stack, OSPri priority, UNK_TYPE arg3, UNK_TYPE arg4, IrqMgr* irqMgr) {
bzero(sc, sizeof(SchedContext));
sc->unk_24C = 1;
osCreateMesgQueue(&sc->interruptQ, sc->intBuf, 8);
osCreateMesgQueue(&sc->cmdQ, sc->cmdMsgBuf, 8);
osSetEventMesg(OS_EVENT_SP, &sc->interruptQ, RSP_DONE_MSG);
osSetEventMesg(OS_EVENT_DP, &sc->interruptQ, RDP_DONE_MSG);
IrqMgr_AddClient(irqMgr, &sc->irqClient, &sc->interruptQ);
osCreateThread(&sc->thread, 5, Sched_ThreadEntry, sc, stack, priority);
osCreateMesgQueue(&sc->interruptQueue, sc->interruptMsgBuf, ARRAY_COUNT(sc->interruptMsgBuf));
osCreateMesgQueue(&sc->cmdQueue, sc->cmdMsgBuf, ARRAY_COUNT(sc->cmdMsgBuf));
osSetEventMesg(OS_EVENT_SP, &sc->interruptQueue, RSP_DONE_MSG);
osSetEventMesg(OS_EVENT_DP, &sc->interruptQueue, RDP_DONE_MSG);
IrqMgr_AddClient(irqMgr, &sc->irqClient, &sc->interruptQueue);
osCreateThread(&sc->thread, THREAD_ID_SCHED, Sched_ThreadEntry, sc, stack, priority);
osStartThread(&sc->thread);
}