12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- #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->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::ArrayIterator<Tickable*> obj = tickSources.begin(); obj; obj++)
- {
- if (obj.val() == zObj)
- {
- obj.remove();
- break;
- }
- }
- sourceCs.unlock();
- }
- void TickOrganizer::exitAndWait()
- {
- queue->requestExit();
- for (int i = 0; i < workerCount; i++)
- {
- workers[i]->warteAufThread(1000000);
- workers[i]->ende();
- workers[i]->release();
- }
- }
|