| 579 | } |
| 580 | |
| 581 | bool TaskScheduler::GetNextLoPriTask(TaskBundle *nextTask) { |
| 582 | unsigned const currentThreadIndex = GetCurrentThreadIndex(); |
| 583 | ThreadLocalStorage &tls = m_tls[currentThreadIndex]; |
| 584 | |
| 585 | // Try to pop from our own queue |
| 586 | if (tls.LoPriTaskQueue.Pop(nextTask)) { |
| 587 | return true; |
| 588 | } |
| 589 | |
| 590 | // Ours is empty, try to steal from the others' |
| 591 | const unsigned threadIndex = tls.LoPriLastSuccessfulSteal; |
| 592 | for (unsigned i = 0; i < m_numThreads; ++i) { |
| 593 | const unsigned threadIndexToStealFrom = (threadIndex + i) % m_numThreads; |
| 594 | if (threadIndexToStealFrom == currentThreadIndex) { |
| 595 | continue; |
| 596 | } |
| 597 | ThreadLocalStorage &otherTLS = m_tls[threadIndexToStealFrom]; |
| 598 | if (otherTLS.LoPriTaskQueue.Steal(nextTask)) { |
| 599 | tls.LoPriLastSuccessfulSteal = threadIndexToStealFrom; |
| 600 | return true; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | unsigned TaskScheduler::GetNextFreeFiberIndex() const { |
| 608 | for (unsigned j = 0;; ++j) { |
no test coverage detected