Skip to content

Commit

Permalink
Merge pull request #88 from accelerated/master
Browse files Browse the repository at this point in the history
Set end iterator to first element of wait queue
  • Loading branch information
Alex Damian authored May 17, 2019
2 parents e398a6e + 30a999e commit ba1b955
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions quantum/impl/quantum_task_queue_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ TaskQueue::TaskListIter TaskQueue::advance()
if ((_queueIt == _runQueue.end()) || (!_isAdvanced && (++_queueIt == _runQueue.end())))
{
acquireWaiting();
_queueIt = _runQueue.begin();
}
_isAdvanced = false; //reset flag
if (_queueIt == _runQueue.end())
Expand All @@ -374,12 +373,31 @@ inline
void TaskQueue::acquireWaiting()
{
//========================= LOCKED SCOPE =========================
SpinLock::Guard lock(_spinlock);
if (!_waitQueue.empty())
if (_waitQueue.empty())
{
_queueIt = _runQueue.begin();
return;
}
bool isEmpty = _runQueue.empty();
if (!isEmpty)
{
//rewind by one since we are at end()
--_queueIt;
}
{
//splice wait queue unto run queue.
SpinLock::Guard lock(_spinlock);
_runQueue.splice(_runQueue.end(), _waitQueue);
}
return;
if (!isEmpty)
{
//move to first element from spliced queue
++_queueIt;
}
else
{
_queueIt = _runQueue.begin();
}
}

}}
Expand Down

0 comments on commit ba1b955

Please sign in to comment.