xref: /netbsd-src/external/bsd/jemalloc/dist/test/src/sleep.c (revision f8cf1a9151c7af1cb0bd8b09c13c66bca599c027)
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 }
28