diff options
Diffstat (limited to 'examples/redis-unstable/deps/jemalloc/test/src/sleep.c')
| -rw-r--r-- | examples/redis-unstable/deps/jemalloc/test/src/sleep.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/jemalloc/test/src/sleep.c b/examples/redis-unstable/deps/jemalloc/test/src/sleep.c new file mode 100644 index 0000000..2234b4b --- /dev/null +++ b/examples/redis-unstable/deps/jemalloc/test/src/sleep.c | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #include "test/jemalloc_test.h" | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Sleep for approximately ns nanoseconds. No lower *nor* upper bound on sleep | ||
| 5 | * time is guaranteed. | ||
| 6 | */ | ||
| 7 | void | ||
| 8 | sleep_ns(unsigned ns) { | ||
| 9 | assert(ns <= 1000*1000*1000); | ||
| 10 | |||
| 11 | #ifdef _WIN32 | ||
| 12 | Sleep(ns / 1000 / 1000); | ||
| 13 | #else | ||
| 14 | { | ||
| 15 | struct timespec timeout; | ||
| 16 | |||
| 17 | if (ns < 1000*1000*1000) { | ||
| 18 | timeout.tv_sec = 0; | ||
| 19 | timeout.tv_nsec = ns; | ||
| 20 | } else { | ||
| 21 | timeout.tv_sec = 1; | ||
| 22 | timeout.tv_nsec = 0; | ||
| 23 | } | ||
| 24 | nanosleep(&timeout, NULL); | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | } | ||
