1234567891011121314151617181920212223242526272829303132 |
- // multitasking.cpp
- // Copyright 2015 MicroNeil Research Corporation
-
- #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 State::Running: { working.put(t); break; }
- case State::Waiting: { waiting.put(t); if(StopOnWait) return; break; }
- case State::Finished: { finished.put(t); break; }
- }
- }
- }
-
- MultiTask::State MultiTasker::task() {
- const bool StopOnFirstWaitingTask = true;
- size_t workingBatchSize = working.size();
- size_t waitingBatchSize = waiting.size();
- processBatch(workingBatchSize, working);
- processBatch(waitingBatchSize, waiting, StopOnFirstWaitingTask);
-
- if(false == working.empty()) { return State::Running; }
- else if (false == waiting.empty()) { return State::Waiting; }
- else { return State::Finished; }
- }
-
- }
|