1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-02-24 00:25:48 +00:00
oot/src/libultra/os/jammesg.c
Tharo 7068ad3703
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
2022-04-08 20:20:23 -04:00

24 lines
643 B
C

#include "global.h"
s32 osJamMesg(OSMesgQueue* mq, OSMesg msg, s32 flag) {
register u32 prevInt = __osDisableInt();
while (MQ_IS_FULL(mq)) {
if (flag == OS_MESG_BLOCK) {
__osRunningThread->state = OS_STATE_WAITING;
__osEnqueueAndYield(&mq->fullqueue);
} else {
__osRestoreInt(prevInt);
return -1;
}
}
mq->first = (mq->first + mq->msgCount - 1) % mq->msgCount;
mq->msg[mq->first] = msg;
mq->validCount++;
if (mq->mtqueue->next != NULL) {
osStartThread(__osPopThread(&mq->mtqueue));
}
__osRestoreInt(prevInt);
return 0;
}