MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / SleepForMicroseconds

Function SleepForMicroseconds

deps/google-benchmark/src/sleep.cc:39–56  ·  view source on GitHub ↗

BENCHMARK_OS_WINDOWS

Source from the content-addressed store, hash-verified

37}
38#else // BENCHMARK_OS_WINDOWS
39void SleepForMicroseconds(int microseconds) {
40#ifdef BENCHMARK_OS_ZOS
41 // z/OS does not support nanosleep. Instead call sleep() and then usleep() to
42 // sleep for the remaining microseconds because usleep() will fail if its
43 // argument is greater than 1000000.
44 div_t sleepTime = div(microseconds, kNumMicrosPerSecond);
45 int seconds = sleepTime.quot;
46 while (seconds != 0) seconds = sleep(seconds);
47 while (usleep(sleepTime.rem) == -1 && errno == EINTR)
48 ;
49#else
50 struct timespec sleep_time;
51 sleep_time.tv_sec = microseconds / kNumMicrosPerSecond;
52 sleep_time.tv_nsec = (microseconds % kNumMicrosPerSecond) * kNumNanosPerMicro;
53 while (nanosleep(&sleep_time, &sleep_time) != 0 && errno == EINTR)
54 ; // Ignore signals and wait for the full interval to elapse.
55#endif
56}
57
58void SleepForMilliseconds(int milliseconds) {
59 SleepForMicroseconds(milliseconds * kNumMicrosPerMilli);

Callers 2

SleepForMillisecondsFunction · 0.85
SleepForSecondsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected