| 774 | |
| 775 | #ifdef _WIN32 |
| 776 | void SleepABit() { |
| 777 | LARGE_INTEGER freq, start, now; |
| 778 | QueryPerformanceFrequency(&freq); |
| 779 | // 1 ms |
| 780 | auto desired = freq.QuadPart / 1000; |
| 781 | if (desired <= 0) { |
| 782 | // Fallback to STL sleep if high resolution clock not available, tests may fail, |
| 783 | // shouldn't really happen |
| 784 | SleepFor(1e-3); |
| 785 | return; |
| 786 | } |
| 787 | QueryPerformanceCounter(&start); |
| 788 | while (true) { |
| 789 | std::this_thread::yield(); |
| 790 | QueryPerformanceCounter(&now); |
| 791 | auto elapsed = now.QuadPart - start.QuadPart; |
| 792 | if (elapsed > desired) { |
| 793 | break; |
| 794 | } |
| 795 | } |
| 796 | } |
| 797 | #else |
| 798 | // std::this_thread::sleep_for should be high enough resolution on non-Windows systems |
| 799 | void SleepABit() { SleepFor(1e-3); } |
no test coverage detected