| 580 | } |
| 581 | |
| 582 | inline |
| 583 | void TaskQueue::acquireWaiting() |
| 584 | { |
| 585 | //========================= LOCKED SCOPE ========================= |
| 586 | SpinLock::Guard lock(_waitQueueLock); |
| 587 | bool isEmpty = _runQueue.empty(); |
| 588 | if (_waitQueue.empty()) |
| 589 | { |
| 590 | if (isEmpty) |
| 591 | { |
| 592 | signalEmptyCondition(true); |
| 593 | } |
| 594 | _queueIt = _runQueue.begin(); |
| 595 | ++_queueRound; |
| 596 | return; |
| 597 | } |
| 598 | if (!isEmpty) |
| 599 | { |
| 600 | //rewind by one since we are at end() |
| 601 | --_queueIt; |
| 602 | } |
| 603 | { |
| 604 | //splice wait queue unto run queue. |
| 605 | _runQueue.splice(_runQueue.end(), _waitQueue); |
| 606 | } |
| 607 | if (!isEmpty) |
| 608 | { |
| 609 | //move to first element from spliced queue |
| 610 | ++_queueIt; |
| 611 | } |
| 612 | else |
| 613 | { |
| 614 | _queueIt = _runQueue.begin(); |
| 615 | ++_queueRound; |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | }} |
| 620 | |