TickOrganizer.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. waiting = 0;
  36. do
  37. {
  38. if( waiting )
  39. queue->waitForEmpty();
  40. for( int i = 0; i < workerCount; i++ )
  41. waiting |= workers[ i ]->isWaiting();
  42. } while( waiting );
  43. }
  44. void TickOrganizer::addTickSource( Block *zBlock )
  45. {
  46. tickSources.add( zBlock );
  47. }
  48. void TickOrganizer::removeTickSource( Block *zBlock )
  49. {
  50. int index = 0;
  51. for( Framework::Iterator<Block *> it = tickSources.getIterator(); it; it++, index++ )
  52. {
  53. if( it == zBlock )
  54. {
  55. tickSources.remove( index );
  56. return;
  57. }
  58. }
  59. }