Clock.h 624 B

1234567891011121314151617181920212223242526272829
  1. #ifndef CLOCK_H
  2. #define CLOCK_H
  3. #include "data/Array.h"
  4. #include "utils/Check.h"
  5. #include "utils/Error.h"
  6. #include "utils/Types.h"
  7. struct Clock final {
  8. typedef int64 Nanos;
  9. private:
  10. static constexpr int BITS = 7;
  11. static constexpr int LENGTH = 1 << BITS;
  12. int index;
  13. Nanos last;
  14. Nanos sum;
  15. Array<Nanos, LENGTH> time;
  16. public:
  17. Clock();
  18. // the first invocation will always return 0 nanos
  19. check_return Error update(Nanos& n);
  20. check_return float getUpdatesPerSecond() const;
  21. check_return Error wait(Nanos nanos) const;
  22. check_return static Error getNanos(Nanos& n);
  23. };
  24. #endif