| 133 | } |
| 134 | |
| 135 | IOS_ERROR IOS_ReceiveMessage(IOSMsgQueueId msgQueueId, IOSMessage* messageOut, uint32 flags) |
| 136 | { |
| 137 | std::unique_lock _l(sInternalMutex); |
| 138 | cemu_assert_debug(flags == 0 || flags == 1); |
| 139 | bool dontBlock = (flags & 1) != 0; |
| 140 | IOSMessageQueue* msgQueue = nullptr; |
| 141 | IOS_ERROR r = _IOS_GetMessageQueue(msgQueueId, msgQueue); |
| 142 | if (r != IOS_ERROR_OK) |
| 143 | return r; |
| 144 | while (true) |
| 145 | { |
| 146 | if (msgQueue->numQueuedMessages == 0) |
| 147 | { |
| 148 | if (dontBlock) |
| 149 | return IOS_ERROR_NONE_AVAILABLE; |
| 150 | } |
| 151 | else |
| 152 | break; |
| 153 | msgQueue->cv_recv.wait(_l); |
| 154 | // after returning from wait, make sure the queue handle is unchanged |
| 155 | if (msgQueue->queueHandle != msgQueueId) |
| 156 | return IOS_ERROR_INVALID; |
| 157 | } |
| 158 | *messageOut = msgQueue->msgArray[(uint32)msgQueue->readIndex]; |
| 159 | msgQueue->readIndex = msgQueue->readIndex + 1; |
| 160 | if (msgQueue->readIndex >= msgQueue->msgArraySize) |
| 161 | msgQueue->readIndex -= msgQueue->msgArraySize; |
| 162 | msgQueue->numQueuedMessages -= 1; |
| 163 | msgQueue->cv_send.notify_one(); |
| 164 | return IOS_ERROR_OK; |
| 165 | } |
| 166 | |
| 167 | /* timer */ |
| 168 |
no test coverage detected