1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-02-23 15:55:47 +00:00
oot/src/libultra/os/startthread.c
Tharo 7068ad3703
Message Queues, Threads, and surroundings cleanup (#1178)
* message queues, threads, and surroundings cleanup

* Format, make the formatter prefer clang-format-11 if found

* Fix __osThreadTail type

* Q -> Queue, thread defines renamed

* Reformat, add missing NULL

* Suggested changes and further casting cleanup

* Reformat

* padmgr name fixes
2022-04-08 20:20:23 -04:00

33 lines
1 KiB
C

#include "global.h"
void osStartThread(OSThread* thread) {
register u32 prevInt = __osDisableInt();
switch (thread->state) {
case OS_STATE_WAITING:
thread->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&__osRunQueue, thread);
break;
case OS_STATE_STOPPED:
if (thread->queue == NULL || thread->queue == &__osRunQueue) {
thread->state = OS_STATE_RUNNABLE;
__osEnqueueThread(&__osRunQueue, thread);
} else {
thread->state = OS_STATE_WAITING;
__osEnqueueThread(thread->queue, thread);
__osEnqueueThread(&__osRunQueue, __osPopThread(thread->queue));
}
break;
}
if (__osRunningThread == NULL) {
__osDispatchThread();
} else {
if (__osRunningThread->priority < __osRunQueue->priority) {
__osRunningThread->state = OS_STATE_RUNNABLE;
__osEnqueueAndYield(&__osRunQueue);
}
}
__osRestoreInt(prevInt);
}