TickWorker.cpp 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "TickWorker.h"
  2. #ifndef _WINDOWS
  3. # include <sys/syscall.h>
  4. # include <unistd.h>
  5. #else
  6. # define pid_t int
  7. #endif
  8. #include "Block.h"
  9. TickWorker::TickWorker(TickQueue* queue)
  10. : Thread(),
  11. queue(queue),
  12. waiting(0)
  13. {
  14. start();
  15. }
  16. TickWorker::~TickWorker() {}
  17. void TickWorker::thread()
  18. {
  19. Tickable* zTick = queue->zNext(waiting);
  20. while (zTick)
  21. {
  22. zTick->tick(queue);
  23. zTick = queue->zNext(waiting);
  24. }
  25. // do not use multiple << here because they are not printed at once with
  26. // multiple threads
  27. pid_t tid;
  28. #ifdef _WINDOWS
  29. tid = (int)(__int64)getThreadHandle();
  30. #else
  31. tid = (pid_t)syscall(SYS_gettid);
  32. #endif
  33. Framework::Text txt = Framework::Text("exiting tick worker ") + tid + "\n";
  34. std::cout << txt.getText();
  35. }
  36. bool TickWorker::isWaiting() const
  37. {
  38. return waiting;
  39. }