TickOrganizer.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. bool waiting = 0;
  27. do
  28. {
  29. if( waiting )
  30. queue->waitForEmpty();
  31. for( int i = 0; i < workerCount; i++ )
  32. waiting |= workers[ i ]->isWaiting();
  33. } while( waiting );
  34. queue->startNextTick( &tickSources );
  35. }
  36. void TickOrganizer::addTickSource( Block *zBlock )
  37. {
  38. tickSources.add( zBlock );
  39. }
  40. void TickOrganizer::removeTickSource( Block *zBlock )
  41. {
  42. int index = 0;
  43. for( Framework::Iterator<Block *> it = tickSources.getIterator(); it; it++, index++ )
  44. {
  45. if( it == zBlock )
  46. {
  47. tickSources.remove( index );
  48. return;
  49. }
  50. }
  51. }