xref: /netbsd-src/external/bsd/jemalloc.old/dist/test/src/mq.c (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
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 mq_nanosleep(unsigned ns) {
9 	assert(ns <= 1000*1000*1000);
10 
11 #ifdef _WIN32
12 	Sleep(ns / 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