123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "TickOrganizer.h"
- #include "Constants.h"
- TickOrganizer::TickOrganizer()
- : ReferenceCounter()
- {
- queue = new TickQueue();
- workerCount = NUM_TICK_WORKERS;
- workers = new TickWorker*[workerCount];
- for (int i = 0; i < workerCount; i++)
- workers[i] = new TickWorker(queue);
- }
- TickOrganizer::~TickOrganizer()
- {
- queue->requestExit();
- for (int i = 0; i < workerCount; i++)
- {
- workers[i]->warteAufThread(10000);
- workers[i]->ende();
- workers[i]->release();
- }
- queue->release();
- delete[] workers;
- }
- void TickOrganizer::nextTick()
- {
- sourceCs.lock();
- queue->startNextTick(&tickSources);
- sourceCs.unlock();
- bool notWaiting = 0;
- do
- {
- queue->waitForEmpty();
- notWaiting = 0;
- for (int i = 0; i < workerCount; i++)
- notWaiting |= !workers[i]->isWaiting();
- } while (notWaiting);
- queue->postTick();
- }
- void TickOrganizer::addTickSource(Tickable* zObj)
- {
- sourceCs.lock();
- tickSources.add(zObj);
- sourceCs.unlock();
- }
- void TickOrganizer::removeTickSource(Tickable* zObj)
- {
- sourceCs.lock();
- for (Framework::Iterator<Tickable*> obj = tickSources.begin(); obj; obj++)
- {
- if (obj.val() == zObj)
- {
- obj.remove();
- break;
- }
- }
- sourceCs.unlock();
- }
|