Imported most of dolphin/os
This commit is contained in:
parent
023cd90675
commit
970da00ce2
35 changed files with 6591 additions and 131 deletions
91
src/dolphin/os/OSMessage.c
Normal file
91
src/dolphin/os/OSMessage.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#include <dolphin/os.h>
|
||||
|
||||
void OSInitMessageQueue(OSMessageQueue *mq, OSMessage *msgArray, s32 msgCount)
|
||||
{
|
||||
OSInitThreadQueue(&mq->queueSend);
|
||||
OSInitThreadQueue(&mq->queueReceive);
|
||||
mq->msgArray = msgArray;
|
||||
mq->msgCount = msgCount;
|
||||
mq->firstIndex = 0;
|
||||
mq->usedCount = 0;
|
||||
}
|
||||
BOOL OSSendMessage(OSMessageQueue *mq, OSMessage msg, s32 flags)
|
||||
{
|
||||
BOOL enabled;
|
||||
s32 lastIndex;
|
||||
|
||||
enabled = OSDisableInterrupts();
|
||||
|
||||
while (mq->msgCount <= mq->usedCount) {
|
||||
if (!(flags & OS_MESSAGE_BLOCK)) {
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
OSSleepThread(&mq->queueSend);
|
||||
}
|
||||
}
|
||||
|
||||
lastIndex = (mq->firstIndex + mq->usedCount) % mq->msgCount;
|
||||
mq->msgArray[lastIndex] = msg;
|
||||
mq->usedCount++;
|
||||
|
||||
OSWakeupThread(&mq->queueReceive);
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL OSReceiveMessage(OSMessageQueue *mq, OSMessage *msg, s32 flags)
|
||||
{
|
||||
BOOL enabled;
|
||||
|
||||
enabled = OSDisableInterrupts();
|
||||
|
||||
while (mq->usedCount == 0) {
|
||||
if (!(flags & OS_MESSAGE_BLOCK)) {
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
OSSleepThread(&mq->queueReceive);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg != NULL) {
|
||||
*msg = mq->msgArray[mq->firstIndex];
|
||||
}
|
||||
mq->firstIndex = (mq->firstIndex + 1) % mq->msgCount;
|
||||
mq->usedCount--;
|
||||
|
||||
OSWakeupThread(&mq->queueSend);
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL OSJamMessage(OSMessageQueue *mq, OSMessage msg, s32 flags)
|
||||
{
|
||||
BOOL enabled;
|
||||
|
||||
enabled = OSDisableInterrupts();
|
||||
|
||||
while (mq->msgCount <= mq->usedCount) {
|
||||
if (!(flags & OS_MESSAGE_BLOCK)) {
|
||||
OSRestoreInterrupts(enabled);
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
OSSleepThread(&mq->queueSend);
|
||||
}
|
||||
}
|
||||
|
||||
mq->firstIndex = (mq->firstIndex + mq->msgCount - 1) % mq->msgCount;
|
||||
mq->msgArray[mq->firstIndex] = msg;
|
||||
mq->usedCount++;
|
||||
|
||||
OSWakeupThread(&mq->queueReceive);
|
||||
|
||||
OSRestoreInterrupts(enabled);
|
||||
return TRUE;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue