TickOrganizer.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "TickOrganizer.h"
  2. #include "Constants.h"
  3. TickOrganizer::TickOrganizer()
  4. : ReferenceCounter()
  5. {
  6. queue = new TickQueue();
  7. workerCount = NUM_TICK_WORKERS;
  8. workers = new TickWorker*[workerCount];
  9. for (int i = 0; i < workerCount; i++)
  10. workers[i] = new TickWorker(queue);
  11. }
  12. TickOrganizer::~TickOrganizer()
  13. {
  14. queue->requestExit();
  15. for (int i = 0; i < workerCount; i++)
  16. {
  17. workers[i]->warteAufThread(10000);
  18. workers[i]->ende();
  19. workers[i]->release();
  20. }
  21. queue->release();
  22. delete[] workers;
  23. }
  24. void TickOrganizer::nextTick()
  25. {
  26. sourceCs.lock();
  27. queue->startNextTick(&tickSources);
  28. sourceCs.unlock();
  29. bool notWaiting = 0;
  30. do
  31. {
  32. queue->waitForEmpty();
  33. notWaiting = 0;
  34. for (int i = 0; i < workerCount; i++)
  35. notWaiting |= !workers[i]->isWaiting();
  36. } while (notWaiting);
  37. queue->postTick();
  38. }
  39. void TickOrganizer::addTickSource(Tickable* zObj)
  40. {
  41. sourceCs.lock();
  42. tickSources.add(zObj);
  43. sourceCs.unlock();
  44. }
  45. void TickOrganizer::removeTickSource(Tickable* zObj)
  46. {
  47. sourceCs.lock();
  48. for (Framework::Iterator<Tickable*> obj = tickSources.begin(); obj; obj++)
  49. {
  50. if (obj.val() == zObj)
  51. {
  52. obj.remove();
  53. break;
  54. }
  55. }
  56. sourceCs.unlock();
  57. }