]> granicus.if.org Git - postgresql/blob - src/port/pgsleep.c
Update copyright for 2006. Update scripts.
[postgresql] / src / port / pgsleep.c
1 /*-------------------------------------------------------------------------
2  *
3  * pgsleep.c
4  *         Portable delay handling.
5  *
6  *
7  * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
8  *
9  * $PostgreSQL: pgsql/src/port/pgsleep.c,v 1.7 2006/03/05 15:59:10 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #include "c.h"
14
15 #include <unistd.h>
16 #include <sys/time.h>
17
18 /*
19  * pg_usleep --- delay the specified number of microseconds.
20  *
21  * NOTE: although the delay is specified in microseconds, the effective
22  * resolution is only 1/HZ, or 10 milliseconds, on most Unixen.  Expect
23  * the requested delay to be rounded up to the next resolution boundary.
24  *
25  * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds.
26  */
27 #ifdef pg_usleep
28 #undef pg_usleep
29 #endif
30 void
31 pg_usleep(long microsec)
32 {
33         if (microsec > 0)
34         {
35 #ifndef WIN32
36                 struct timeval delay;
37
38                 delay.tv_sec = microsec / 1000000L;
39                 delay.tv_usec = microsec % 1000000L;
40                 (void) select(0, NULL, NULL, NULL, &delay);
41 #else
42                 SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE);
43 #endif
44         }
45 }