| 261 | } |
| 262 | |
| 263 | static OSThread* SelectThread(BOOL yield) |
| 264 | { |
| 265 | OSContext* currentContext; |
| 266 | OSThread* currentThread; |
| 267 | OSThread* nextThread; |
| 268 | OSPriority priority; |
| 269 | OSThreadQueue* queue; |
| 270 | |
| 271 | if (0 < Reschedule) |
| 272 | { |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | currentContext = OSGetCurrentContext(); |
| 277 | currentThread = OSGetCurrentThread(); |
| 278 | if (currentContext != ¤tThread->context) |
| 279 | { |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | if (currentThread) |
| 284 | { |
| 285 | if (currentThread->state == OS_THREAD_STATE_RUNNING) |
| 286 | { |
| 287 | if (!yield) |
| 288 | { |
| 289 | priority = __cntlzw(RunQueueBits); |
| 290 | if (currentThread->priority <= priority) |
| 291 | { |
| 292 | return 0; |
| 293 | } |
| 294 | } |
| 295 | currentThread->state = OS_THREAD_STATE_READY; |
| 296 | SetRun(currentThread); |
| 297 | } |
| 298 | |
| 299 | if (!(currentThread->context.state & OS_CONTEXT_STATE_EXC) && |
| 300 | OSSaveContext(¤tThread->context)) |
| 301 | { |
| 302 | return 0; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | if (RunQueueBits == 0) |
| 307 | { |
| 308 | SwitchThreadCallback(__OSCurrentThread, NULL); |
| 309 | __OSCurrentThread = NULL; |
| 310 | OSSetCurrentContext(&IdleContext); |
| 311 | do |
| 312 | { |
| 313 | OSEnableInterrupts(); |
| 314 | while (RunQueueBits == 0) |
| 315 | ; |
| 316 | OSDisableInterrupts(); |
| 317 | } while (RunQueueBits == 0); |
| 318 | |
| 319 | OSClearContext(&IdleContext); |
| 320 | } |
no test coverage detected