1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-08-10 08:50:23 +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

@ -44,10 +44,10 @@ s32 __osContRamWrite(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer, s32
ret = __osSiRawStartDma(OS_WRITE, &gPifMempakBuf);
crc = __osContDataCrc(buffer);
osRecvMesg(mq, (OSMesg*)NULL, OS_MESG_BLOCK);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
ret = __osSiRawStartDma(OS_READ, &gPifMempakBuf);
osRecvMesg(mq, (OSMesg*)NULL, OS_MESG_BLOCK);
osRecvMesg(mq, NULL, OS_MESG_BLOCK);
ret = ((((__OSContRamHeader*)ptr)->rxsize & 0xC0) >> 4);
if (!ret) {

View file

@ -5,7 +5,7 @@ u8 __osContLastPoll;
u8 __osMaxControllers; // always 4
OSTimer __osEepromTimer;
OSMesgQueue __osEepromTimerMsgQ;
OSMesgQueue __osEepromTimerMsgQueue;
OSMesg __osEepromTimerMsg;
u32 gOSContInitialized = 0;
@ -13,7 +13,7 @@ u32 gOSContInitialized = 0;
#define HALF_SECOND OS_USEC_TO_CYCLES(500000)
s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) {
OSMesg mesg;
OSMesg msg;
s32 ret = 0;
OSTime currentTime;
OSTimer timer;
@ -26,20 +26,20 @@ s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) {
gOSContInitialized = 1;
currentTime = osGetTime();
if (HALF_SECOND > currentTime) {
osCreateMesgQueue(&timerqueue, &mesg, 1);
osSetTimer(&timer, HALF_SECOND - currentTime, 0, &timerqueue, &mesg);
osRecvMesg(&timerqueue, &mesg, OS_MESG_BLOCK);
osCreateMesgQueue(&timerqueue, &msg, 1);
osSetTimer(&timer, HALF_SECOND - currentTime, 0, &timerqueue, &msg);
osRecvMesg(&timerqueue, &msg, OS_MESG_BLOCK);
}
__osMaxControllers = MAXCONTROLLERS;
__osPackRequestData(CONT_CMD_REQUEST_STATUS);
ret = __osSiRawStartDma(OS_WRITE, &__osPifInternalBuff);
osRecvMesg(mq, &mesg, OS_MESG_BLOCK);
osRecvMesg(mq, &msg, OS_MESG_BLOCK);
ret = __osSiRawStartDma(OS_READ, &__osPifInternalBuff);
osRecvMesg(mq, &mesg, OS_MESG_BLOCK);
osRecvMesg(mq, &msg, OS_MESG_BLOCK);
__osContGetInitData(ctlBitfield, status);
__osContLastPoll = CONT_CMD_REQUEST_STATUS;
__osSiCreateAccessQueue();
osCreateMesgQueue(&__osEepromTimerMsgQ, &__osEepromTimerMsg, 1);
osCreateMesgQueue(&__osEepromTimerMsgQueue, &__osEepromTimerMsg, 1);
return ret;
}

View file

@ -15,7 +15,7 @@ void __osDevMgrMain(void* arg) {
ioMesg = NULL;
while (true) {
osRecvMesg(arg0->cmdQueue, (OSMesg)&ioMesg, OS_MESG_BLOCK);
osRecvMesg(arg0->cmdQueue, (OSMesg*)&ioMesg, OS_MESG_BLOCK);
if ((ioMesg->piHandle != NULL) && (ioMesg->piHandle->type == DEVICE_TYPE_64DD) &&
((ioMesg->piHandle->transferInfo.cmdType == 0) || (ioMesg->piHandle->transferInfo.cmdType == 1))) {
transfer = &ioMesg->piHandle->transferInfo;
@ -46,7 +46,7 @@ void __osDevMgrMain(void* arg) {
HW_REG(PI_STATUS_REG, u32) = PI_STATUS_CLEAR_INTR;
__osSetGlobalIntMask(0x00100C01);
}
osSendMesg(ioMesg->hdr.retQueue, ioMesg, OS_MESG_NOBLOCK);
osSendMesg(ioMesg->hdr.retQueue, (OSMesg)ioMesg, OS_MESG_NOBLOCK);
if ((phi_s2 != 1) || (ioMesg->piHandle->transferInfo.block[0].errStatus != 0)) {
break;
@ -55,7 +55,7 @@ void __osDevMgrMain(void* arg) {
phi_s2 = 0;
}
osSendMesg(arg0->acccessQueue, 0, OS_MESG_NOBLOCK);
osSendMesg(arg0->acccessQueue, NULL, OS_MESG_NOBLOCK);
if (ioMesg->piHandle->transferInfo.blockNum == 1) {
osYieldThread();
}
@ -80,7 +80,7 @@ void __osDevMgrMain(void* arg) {
ioMesg->size);
break;
case OS_MESG_TYPE_LOOPBACK:
osSendMesg(ioMesg->hdr.retQueue, ioMesg, OS_MESG_NOBLOCK);
osSendMesg(ioMesg->hdr.retQueue, (OSMesg)ioMesg, OS_MESG_NOBLOCK);
phi_s0 = -1;
break;
default:
@ -90,7 +90,7 @@ void __osDevMgrMain(void* arg) {
if (phi_s0 == 0) {
osRecvMesg(arg0->eventQueue, &sp70, OS_MESG_BLOCK);
osSendMesg(ioMesg->hdr.retQueue, ioMesg, OS_MESG_NOBLOCK);
osSendMesg(ioMesg->hdr.retQueue, (OSMesg)ioMesg, OS_MESG_NOBLOCK);
osSendMesg(arg0->acccessQueue, NULL, OS_MESG_NOBLOCK);
}
}

View file

@ -1,24 +1,23 @@
#include "global.h"
u32 __osPiAccessQueueEnabled = 0;
OSMesg piAccessBuf;
u32 __osPiAccessQueueEnabled = false;
OSMesg piAccessBuf[1];
OSMesgQueue __osPiAccessQueue;
void __osPiCreateAccessQueue(void) {
__osPiAccessQueueEnabled = 1;
osCreateMesgQueue(&__osPiAccessQueue, &piAccessBuf, 1);
__osPiAccessQueueEnabled = true;
osCreateMesgQueue(&__osPiAccessQueue, piAccessBuf, ARRAY_COUNT(piAccessBuf));
osSendMesg(&__osPiAccessQueue, NULL, OS_MESG_NOBLOCK);
}
void __osPiGetAccess(void) {
OSMesg mesg;
OSMesg msg;
if (!__osPiAccessQueueEnabled) {
__osPiCreateAccessQueue();
}
osRecvMesg(&__osPiAccessQueue, &mesg, OS_MESG_BLOCK);
osRecvMesg(&__osPiAccessQueue, &msg, OS_MESG_BLOCK);
}
void __osPiRelAccess(void) {

View file

@ -17,13 +17,13 @@ OSPiHandle* __osCurrentHandle[] = {
&__Dom2SpeedParam,
};
void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgCnt) {
void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQueue, OSMesg* cmdBuf, s32 cmdMsgCnt) {
u32 prevInt;
OSPri newPri;
OSPri currentPri;
if (!__osPiDevMgr.initialized) {
osCreateMesgQueue(cmdQ, cmdBuf, cmdMsgCnt);
osCreateMesgQueue(cmdQueue, cmdBuf, cmdMsgCnt);
osCreateMesgQueue(&piEventQueue, piEventBuf, 1);
if (!__osPiAccessQueueEnabled) {
__osPiCreateAccessQueue();
@ -39,7 +39,7 @@ void osCreatePiManager(OSPri pri, OSMesgQueue* cmdQ, OSMesg* cmdBuf, s32 cmdMsgC
prevInt = __osDisableInt();
__osPiDevMgr.initialized = true;
__osPiDevMgr.cmdQueue = cmdQ;
__osPiDevMgr.cmdQueue = cmdQueue;
__osPiDevMgr.mgrThread = &piThread;
__osPiDevMgr.eventQueue = &piEventQueue;
__osPiDevMgr.acccessQueue = &__osPiAccessQueue;

View file

@ -1,24 +1,24 @@
#include "global.h"
OSMesg osSiMesgBuff[SIAccessQueueSize];
OSMesgQueue gOSSiMessageQueue;
u32 gOSSiAccessQueueCreated = 0;
OSMesg siAccessBuf[1];
OSMesgQueue __osSiAccessQueue;
u32 __osSiAccessQueueEnabled = false;
void __osSiCreateAccessQueue(void) {
gOSSiAccessQueueCreated = 1;
osCreateMesgQueue(&gOSSiMessageQueue, &osSiMesgBuff[0], SIAccessQueueSize - 1);
osSendMesg(&gOSSiMessageQueue, NULL, OS_MESG_NOBLOCK);
__osSiAccessQueueEnabled = true;
osCreateMesgQueue(&__osSiAccessQueue, siAccessBuf, ARRAY_COUNT(siAccessBuf));
osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK);
}
void __osSiGetAccess(void) {
OSMesg mesg;
OSMesg msg;
if (!gOSSiAccessQueueCreated) {
if (!__osSiAccessQueueEnabled) {
__osSiCreateAccessQueue();
}
osRecvMesg(&gOSSiMessageQueue, &mesg, OS_MESG_BLOCK);
osRecvMesg(&__osSiAccessQueue, &msg, OS_MESG_BLOCK);
}
void __osSiRelAccess(void) {
osSendMesg(&gOSSiMessageQueue, NULL, OS_MESG_NOBLOCK);
osSendMesg(&__osSiAccessQueue, NULL, OS_MESG_NOBLOCK);
}

View file

@ -4,7 +4,7 @@
OSThread viThread;
STACK(viThreadStack, 0x1000);
OSMesgQueue viEventQueue;
OSMesg viEventBuf[6];
OSMesg viEventBuf[5];
OSIoMesg viRetraceMsg;
OSIoMesg viCounterMsg;
OSMgrArgs __osViDevMgr = { 0 };
@ -20,7 +20,7 @@ void osCreateViManager(OSPri pri) {
if (!__osViDevMgr.initialized) {
__osTimerServicesInit();
__additional_scanline = 0;
osCreateMesgQueue(&viEventQueue, viEventBuf, 5);
osCreateMesgQueue(&viEventQueue, viEventBuf, ARRAY_COUNT(viEventBuf));
viRetraceMsg.hdr.type = OS_MESG_TYPE_VRETRACE;
viRetraceMsg.hdr.pri = OS_MESG_PRI_NORMAL;
viRetraceMsg.hdr.retQueue = NULL;
@ -59,7 +59,7 @@ void viMgrMain(void* vargs) {
static u16 viRetrace;
OSMgrArgs* args;
u32 addTime;
OSIoMesg* mesg = NULL;
OSIoMesg* msg = NULL;
u32 temp = 0; // always 0
viRetrace = __osViGetCurrentContext()->retraceCount;
@ -70,8 +70,8 @@ void viMgrMain(void* vargs) {
args = (OSMgrArgs*)vargs;
while (true) {
osRecvMesg(args->eventQueue, (OSMesg)&mesg, OS_MESG_BLOCK);
switch (mesg->hdr.type) {
osRecvMesg(args->eventQueue, (OSMesg*)&msg, OS_MESG_BLOCK);
switch (msg->hdr.type) {
case OS_MESG_TYPE_VRETRACE:
__osViSwapContext();
viRetrace--;

View file

@ -1,8 +1,8 @@
#include "global.h"
void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msg, s32 count) {
mq->mtqueue = (OSThread*)__osThreadTail;
mq->fullqueue = (OSThread*)__osThreadTail;
mq->mtqueue = (OSThread*)&__osThreadTail;
mq->fullqueue = (OSThread*)&__osThreadTail;
mq->validCount = 0;
mq->first = 0;
mq->msgCount = count;

View file

@ -1,8 +1,8 @@
#include "global.h"
OSThread* __osThreadTail[2] = { NULL, (OSThread*)OS_PRIORITY_THREADTAIL };
OSThread* __osRunQueue = (OSThread*)__osThreadTail;
OSThread* __osActiveQueue = (OSThread*)__osThreadTail;
__OSThreadTail __osThreadTail = { NULL, OS_PRIORITY_THREADTAIL };
OSThread* __osRunQueue = (OSThread*)&__osThreadTail;
OSThread* __osActiveQueue = (OSThread*)&__osThreadTail;
OSThread* __osRunningThread = NULL;
OSThread* __osFaultedThread = NULL;
@ -20,8 +20,8 @@ void osCreateThread(OSThread* thread, OSId id, void (*entry)(void*), void* arg,
thread->context.ra = __osCleanupThread;
mask = OS_IM_ALL;
thread->context.sr = (mask & OS_IM_CPU) | 2;
thread->context.rcp = (mask & RCP_IMASK) >> 16;
thread->context.sr = (mask & OS_IM_CPU) | SR_EXL;
thread->context.rcp = (mask & RCP_IMASK) >> RCP_IMASKSHIFT;
thread->context.fpcsr = FPCSR_FS | FPCSR_EV;
thread->fp = 0;
thread->state = OS_STATE_STOPPED;

View file

@ -3,7 +3,7 @@
s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) {
register u32 prevInt = __osDisableInt();
while (mq->validCount >= mq->msgCount) {
while (MQ_IS_FULL(mq)) {
if (flag == OS_MESG_BLOCK) {
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->fullqueue);

View file

@ -3,12 +3,12 @@
s32 osRecvMesg(OSMesgQueue* mq, OSMesg* msg, s32 flag) {
register u32 prevInt = __osDisableInt();
while (mq->validCount == 0) {
while (MQ_IS_EMPTY(mq)) {
if (flag == OS_MESG_NOBLOCK) {
__osRestoreInt(prevInt);
return -1;
}
__osRunningThread->state = 8;
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield((OSThread**)mq);
}

View file

@ -1,12 +1,12 @@
#include "global.h"
s32 osSendMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag) {
s32 osSendMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) {
register u32 prevInt = __osDisableInt();
register u32 index;
while (mq->validCount >= mq->msgCount) {
while (MQ_IS_FULL(mq)) {
if (flag == OS_MESG_BLOCK) {
__osRunningThread->state = 8;
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->fullqueue);
} else {
__osRestoreInt(prevInt);
@ -15,7 +15,7 @@ s32 osSendMesg(OSMesgQueue* mq, OSMesg mesg, s32 flag) {
}
index = (mq->first + mq->validCount) % mq->msgCount;
mq->msg[index] = mesg;
mq->msg[index] = msg;
mq->validCount++;
if (mq->mtqueue->next != NULL) {

View file

@ -9,12 +9,12 @@ void osSetThreadPri(OSThread* thread, OSPri pri) {
if (thread->priority != pri) {
thread->priority = pri;
if (thread != __osRunningThread && thread->state != 1) {
if (thread != __osRunningThread && thread->state != OS_STATE_STOPPED) {
__osDequeueThread(thread->queue, thread);
__osEnqueueThread(thread->queue, thread);
}
if (__osRunningThread->priority < __osRunQueue->priority) {
__osRunningThread->state = 2;
__osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&__osRunQueue);
}
}

View file

@ -4,16 +4,16 @@ void osStartThread(OSThread* thread) {
register u32 prevInt = __osDisableInt();
switch (thread->state) {
case 8:
thread->state = 2;
case OS_STATE_WAITING:
thread->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&__osRunQueue, thread);
break;
case 1:
case OS_STATE_STOPPED:
if (thread->queue == NULL || thread->queue == &__osRunQueue) {
thread->state = 2;
thread->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&__osRunQueue, thread);
} else {
thread->state = 8;
thread->state = OS_STATE_WAITING;
__osEnqueueThread(thread->queue, thread);
__osEnqueueThread(&__osRunQueue, __osPopThread(thread->queue));
}
@ -24,7 +24,7 @@ void osStartThread(OSThread* thread) {
__osDispatchThread();
} else {
if (__osRunningThread->priority < __osRunQueue->priority) {
__osRunningThread->state = 2;
__osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&__osRunQueue);
}
}

View file

@ -5,19 +5,19 @@ void osStopThread(OSThread* thread) {
register u32 state;
if (thread == NULL) {
state = 4;
state = OS_STATE_RUNNING;
} else {
state = thread->state;
}
switch (state) {
case 4:
__osRunningThread->state = 1;
case OS_STATE_RUNNING:
__osRunningThread->state = OS_STATE_STOPPED;
__osEnqueueAndYield(NULL);
break;
case 2:
case 8:
thread->state = 1;
case OS_STATE_RUNNABLE:
case OS_STATE_WAITING:
thread->state = OS_STATE_STOPPED;
__osDequeueThread(thread->queue, thread);
break;
}