slow_clock.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // -*- C++ -*-
  2. // Copyright (C) 2018-2022 Free Software Foundation, Inc.
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License as
  5. // published by the Free Software Foundation; either version 3, or (at
  6. // your option) any later version.
  7. // This library is distributed in the hope that it will be useful, but
  8. // WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. // General Public License for more details.
  11. // You should have received a copy of the GNU General Public License
  12. // along with this library; see the file COPYING3. If not see
  13. // <http://www.gnu.org/licenses/>.
  14. // A clock that ticks at a third of the speed of system_clock that can be used
  15. // to ensure that functions with timeouts don't erroneously return early.
  16. #include <chrono>
  17. namespace __gnu_test
  18. {
  19. struct slow_clock
  20. {
  21. using rep = std::chrono::system_clock::rep;
  22. using period = std::chrono::system_clock::period;
  23. using duration = std::chrono::system_clock::duration;
  24. using time_point = std::chrono::time_point<slow_clock, duration>;
  25. static constexpr bool is_steady = false;
  26. static time_point now()
  27. {
  28. auto real = std::chrono::system_clock::now();
  29. return time_point{real.time_since_epoch() / 3};
  30. }
  31. };
  32. }