TickWorker.cpp 894 B

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