MCPcopy Create free account
hub / github.com/cemu-project/Cemu / OSSendMessage

Function OSSendMessage

src/Cafe/OS/libs/coreinit/coreinit_MessageQueue.cpp:82–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80 }
81
82 sint32 OSSendMessage(OSMessageQueue* msgQueue, OSMessage* msg, uint32 flags)
83 {
84 __OSLockScheduler();
85 while (msgQueue->usedCount >= msgQueue->msgCount)
86 {
87 if ((flags & OS_MESSAGE_BLOCK))
88 {
89 msgQueue->threadQueueSend.queueAndWait(OSGetCurrentThread());
90 }
91 else
92 {
93 __OSUnlockScheduler();
94 return 0;
95 }
96 }
97 // add message
98 if ((flags & OS_MESSAGE_HIGH_PRIORITY))
99 {
100 // decrease firstIndex
101 sint32 newFirstIndex = (sint32)((sint32)msgQueue->firstIndex + (sint32)msgQueue->msgCount - 1) % (sint32)msgQueue->msgCount;
102 msgQueue->firstIndex = newFirstIndex;
103 // insert message at new first index
104 msgQueue->usedCount = (uint32)msgQueue->usedCount + 1;
105 OSMessage* newMsg = &(msgQueue->msgArray[newFirstIndex]);
106 memcpy(newMsg, msg, sizeof(OSMessage));
107 }
108 else
109 {
110 sint32 messageIndex = (uint32)(msgQueue->firstIndex + msgQueue->usedCount) % (uint32)msgQueue->msgCount;
111 msgQueue->usedCount = (uint32)msgQueue->usedCount + 1;
112 OSMessage* newMsg = &(msgQueue->msgArray[messageIndex]);
113 memcpy(newMsg, msg, sizeof(OSMessage));
114 }
115 // wake up any thread waiting to read a message
116 if (!msgQueue->threadQueueReceive.isEmpty())
117 msgQueue->threadQueueReceive.wakeupSingleThreadWaitQueue(true);
118 __OSUnlockScheduler();
119 return 1;
120 }
121
122 OSMessageQueue* OSGetSystemMessageQueue()
123 {

Callers 5

AXIst_QueueFrameFunction · 0.85
AXIst_StopThreadFunction · 0.85
UpdateSystemMessageQueueFunction · 0.85
__FSCmdSubmitResultFunction · 0.85
IPCDriver_HandleResponseFunction · 0.85

Calls 6

__OSLockSchedulerFunction · 0.85
OSGetCurrentThreadFunction · 0.85
__OSUnlockSchedulerFunction · 0.85
queueAndWaitMethod · 0.80
isEmptyMethod · 0.45

Tested by

no test coverage detected