Преглед на файлове

Use enum class, and put classes in CodeDweller namespace.


git-svn-id: https://svn.microneil.com/svn/CodeDweller/branches/adeniz_1@103 d34b734f-a00e-4b39-a726-e4eeb87269ab
adeniz_1
adeniz преди 9 години
родител
ревизия
9acdc5bd8b
променени са 2 файла, в които са добавени 19 реда и са изтрити 11 реда
  1. 13
    8
      multitasking.cpp
  2. 6
    3
      multitasking.hpp

+ 13
- 8
multitasking.cpp Целия файл

@@ -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; }
}

+ 6
- 3
multitasking.hpp Целия файл

@@ -4,11 +4,12 @@
#include <cstddef>
#include <queue>

enum MultiTaskState {Running, Waiting, Finished};
namespace CodeDweller {

class MultiTask {
public:
virtual MultiTaskState task() = 0;
enum class State{Running, Waiting, Finished};
virtual State task() = 0;
};

class MultiTaskQueue : public std::queue<MultiTask*> {
@@ -27,7 +28,7 @@ class MultiTasker : public MultiTask {
MultiTaskQueue working;
MultiTaskQueue waiting;
MultiTaskQueue finished;
MultiTaskState task();
State task();

bool isReady() { return (false == working.empty()); }
bool isWaiting() { return (false == waiting.empty() && true == working.empty()); }
@@ -43,4 +44,6 @@ class MultiTasker : public MultiTask {
bool canGet() { return (false == finished.empty()); }
};

}

#endif // M_MultiTasking

Loading…
Отказ
Запис