TickOrganizer.cpp 1.2 KB

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