MCPcopy Create free account
hub / github.com/doldecomp/mkdd / SelectThread

Function SelectThread

libs/dolphin/os/OSThread.c:251–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

249}
250
251static OSThread *SelectThread(BOOL yield)
252{
253 OSContext *currentContext;
254 OSThread *currentThread;
255 OSThread *nextThread;
256 OSPriority priority;
257 OSThreadQueue *queue;
258
259 if (0 < Reschedule)
260 {
261 return 0;
262 }
263
264 currentContext = OSGetCurrentContext();
265 currentThread = OSGetCurrentThread();
266 if (currentContext != &currentThread->context)
267 {
268 return 0;
269 }
270
271 if (currentThread)
272 {
273 if (currentThread->state == OS_THREAD_STATE_RUNNING)
274 {
275 if (!yield)
276 {
277 priority = __cntlzw(RunQueueBits);
278 if (currentThread->priority <= priority)
279 {
280 return 0;
281 }
282 }
283 currentThread->state = OS_THREAD_STATE_READY;
284 SetRun(currentThread);
285 }
286
287 if (!(currentThread->context.state & OS_CONTEXT_STATE_EXC) && OSSaveContext(&currentThread->context))
288 {
289 return 0;
290 }
291 }
292
293 if (RunQueueBits == 0)
294 {
295 SwitchThreadCallback(__OSCurrentThread, nullptr);
296 __OSCurrentThread = nullptr;
297 OSSetCurrentContext(&IdleContext);
298 do
299 {
300 OSEnableInterrupts();
301 while (RunQueueBits == 0)
302 ;
303 OSDisableInterrupts();
304 } while (RunQueueBits == 0);
305
306 OSClearContext(&IdleContext);
307 }
308

Callers 3

__OSRescheduleFunction · 0.85
OSYieldThreadFunction · 0.85
OSExitThreadFunction · 0.85

Calls 4

OSGetCurrentThreadFunction · 0.85
SetRunFunction · 0.85
OSDisableInterruptsFunction · 0.85
__OSSwitchThreadFunction · 0.85

Tested by

no test coverage detected