1 /**
2  * @file sleep.c  System sleep functions
3  *
4  * Copyright (C) 2010 Creytiv.com
5  */
6 #include <re_types.h>
7 #include <re_fmt.h>
8 #include <re_sys.h>
9 #ifdef WIN32
10 #include <windows.h>
11 #endif
12 #ifdef HAVE_UNISTD_H
13 #define _BSD_SOURCE 1
14 #include <unistd.h>
15 #endif
16 #ifdef HAVE_SELECT_H
17 #include <sys/select.h>
18 #endif
19 
20 
21 /**
22  * Blocking sleep for [us] number of microseconds
23  *
24  * @param us Number of microseconds to sleep
25  */
sys_usleep(unsigned int us)26 void sys_usleep(unsigned int us)
27 {
28 	if (!us)
29 		return;
30 
31 #ifdef WIN32
32 	Sleep(us / 1000);
33 #elif defined(HAVE_SELECT)
34 	do {
35 		struct timeval tv;
36 
37 		tv.tv_sec  = us / 1000000;
38 		tv.tv_usec = us % 1000000;
39 
40 		(void)select(0, NULL, NULL, NULL, &tv);
41 	} while (0);
42 #else
43 	(void)usleep(us);
44 #endif
45 }
46