Projekty z kursu Systemy operacyjne 2 na PWr
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Stopwatch.cpp 555B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "Stopwatch.h"
  2. Stopwatch::Stopwatch()
  3. {
  4. //ctor
  5. // Jan Potocki 2018
  6. }
  7. void Stopwatch::start()
  8. {
  9. running = true;
  10. miliseconds = 0;
  11. measureThread = std::thread(&Stopwatch::measure, this);
  12. }
  13. void Stopwatch::stop()
  14. {
  15. running = false;
  16. measureThread.join();
  17. }
  18. bool Stopwatch::isRunning()
  19. {
  20. return running;
  21. }
  22. float Stopwatch::read()
  23. {
  24. float measurement = (float)miliseconds / 1000;
  25. return measurement;
  26. }
  27. void Stopwatch::measure()
  28. {
  29. while(running)
  30. {
  31. usleep(1000);
  32. miliseconds++;
  33. }
  34. }