您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132
  1. // multitasking.cpp
  2. // Copyright 2015 MicroNeil Research Corporation
  3. #include "multitasking.hpp"
  4. namespace CodeDweller {
  5. void MultiTasker::processBatch(size_t n, MultiTaskQueue& q, bool StopOnWait) {
  6. size_t batchSize = n;
  7. while(batchSize--) {
  8. MultiTask& t = q.get();
  9. switch(t.task()) {
  10. case State::Running: { working.put(t); break; }
  11. case State::Waiting: { waiting.put(t); if(StopOnWait) return; break; }
  12. case State::Finished: { finished.put(t); break; }
  13. }
  14. }
  15. }
  16. MultiTask::State MultiTasker::task() {
  17. const bool StopOnFirstWaitingTask = true;
  18. size_t workingBatchSize = working.size();
  19. size_t waitingBatchSize = waiting.size();
  20. processBatch(workingBatchSize, working);
  21. processBatch(waitingBatchSize, waiting, StopOnFirstWaitingTask);
  22. if(false == working.empty()) { return State::Running; }
  23. else if (false == waiting.empty()) { return State::Waiting; }
  24. else { return State::Finished; }
  25. }
  26. }