|
|
@@ -3,25 +3,30 @@ |
|
|
|
|
|
|
|
#include "multitasking.hpp" |
|
|
|
|
|
|
|
namespace CodeDweller { |
|
|
|
|
|
|
|
void MultiTasker::processBatch(size_t n, MultiTaskQueue& q, bool StopOnWait) { |
|
|
|
size_t batchSize = n; |
|
|
|
while(batchSize--) { |
|
|
|
MultiTask& t = q.get(); |
|
|
|
switch(t.task()) { |
|
|
|
case Running: { working.put(t); break; } |
|
|
|
case Waiting: { waiting.put(t); if(StopOnWait) return; break; } |
|
|
|
case Finished: { finished.put(t); break; } |
|
|
|
case State::Running: { working.put(t); break; } |
|
|
|
case State::Waiting: { waiting.put(t); if(StopOnWait) return; break; } |
|
|
|
case State::Finished: { finished.put(t); break; } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
MultiTaskState MultiTasker::task() { |
|
|
|
MultiTask::State MultiTasker::task() { |
|
|
|
const bool StopOnFirstWaitingTask = true; |
|
|
|
size_t workingBatchSize = working.size(); |
|
|
|
size_t waitingBatchSize = waiting.size(); |
|
|
|
processBatch(workingBatchSize, working); |
|
|
|
processBatch(waitingBatchSize, waiting, true); |
|
|
|
processBatch(waitingBatchSize, waiting, StopOnFirstWaitingTask); |
|
|
|
|
|
|
|
if(false == working.empty()) { return State::Running; } |
|
|
|
else if (false == waiting.empty()) { return State::Waiting; } |
|
|
|
else { return State::Finished; } |
|
|
|
} |
|
|
|
|
|
|
|
if(false == working.empty()) { return Running; } |
|
|
|
else if (false == waiting.empty()) { return Waiting; } |
|
|
|
else { return Finished; } |
|
|
|
} |