Shipwright/soh/src/libultra/os/recvmesg.c
M4xw 39cc86c260 git subrepo clone https://github.com/HarbourMasters/soh.git
subrepo:
  subdir:   "soh"
  merged:   "ba904bbd0"
upstream:
  origin:   "https://github.com/HarbourMasters/soh.git"
  branch:   "master"
  commit:   "ba904bbd0"
git-subrepo:
  version:  "0.4.1"
  origin:   "???"
  commit:   "???"
2022-03-22 02:51:23 +01:00

30 lines
639 B
C

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