40#ifdef F__thread_internals
50static void topThread(
void *arg)
58 index =
topArg.requestOut & 0x1FF;
59 topArg.requestOut = index + 1;
61 switch (
topArg.request[index].mode) {
63 WakeupThread(
topArg.request[index].data);
66 RotateThreadReadyQueue(
topArg.request[index].data);
69 SuspendThread(
topArg.request[index].data);
85 sema.option = (u32)
"KernelTopThread";
86 if ((topSema = CreateSema(&sema)) < 0)
91 thread.stack_size =
sizeof(stack);
93 thread.option = (u32)
"KernelTopThread";
94 thread.initial_priority = 0;
95 if ((topId = CreateThread(&
thread)) < 0) {
102 StartThread(topId, &
topArg);
104 ChangeThreadPriority(GetThreadId(), 1);
110#ifdef F_iWakeupThread
113s32 iWakeupThread(s32 thread_id)
115 if (_iGetThreadId() == thread_id) {
116 if (thread_id < 256 && topId != 0) {
119 index =
topArg.requestIn & 0x1FF;
120 topArg.requestIn = index + 1;
121 topArg.request[index].mode = TOP_REQ_WAKEUP;
122 topArg.request[index].data = thread_id;
124 iSignalSema(topSema);
129 return _iWakeupThread(thread_id);
134#ifdef F_iRotateThreadReadyQueue
137s32 iRotateThreadReadyQueue(s32 priority)
139 if (priority < 128 && topId != 0) {
142 index =
topArg.requestIn & 0x1FF;
143 topArg.requestIn = index + 1;
144 topArg.request[index].mode = TOP_REQ_ROTATE;
145 topArg.request[index].data = priority;
147 iSignalSema(topSema);
154#ifdef F_iSuspendThread
157s32 iSuspendThread(s32 thread_id)
159 if (_iGetThreadId() == thread_id) {
160 if (thread_id < 256 && topId != 0) {
163 index =
topArg.requestIn & 0x1FF;
164 topArg.requestIn = index + 1;
165 topArg.request[index].mode = TOP_REQ_SUSPEND;
166 topArg.request[index].data = thread_id;
168 iSignalSema(topSema);
173 return _iSuspendThread(thread_id);