| 249 | } |
| 250 | |
| 251 | static 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 != ¤tThread->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(¤tThread->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 |
no test coverage detected