]> granicus.if.org Git - postgresql/blob - src/port/pgsleep.c
Don't zero opfuncid when reading nodes.
[postgresql] / src / port / pgsleep.c
1 /*-------------------------------------------------------------------------
2  *
3  * pgsleep.c
4  *         Portable delay handling.
5  *
6  *
7  * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
8  *
9  * src/port/pgsleep.c
10  *
11  *-------------------------------------------------------------------------
12  */
13 #include "c.h"
14
15 #include <unistd.h>
16 #include <sys/time.h>
17
18 /*
19  * In a Windows backend, we don't use this implementation, but rather
20  * the signal-aware version in src/backend/port/win32/signal.c.
21  */
22 #if defined(FRONTEND) || !defined(WIN32)
23
24 /*
25  * pg_usleep --- delay the specified number of microseconds.
26  *
27  * NOTE: although the delay is specified in microseconds, the effective
28  * resolution is only 1/HZ, or 10 milliseconds, on most Unixen.  Expect
29  * the requested delay to be rounded up to the next resolution boundary.
30  *
31  * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds.
32  *
33  * CAUTION: the behavior when a signal arrives during the sleep is platform
34  * dependent.  On most Unix-ish platforms, a signal does not terminate the
35  * sleep; but on some, it will (the Windows implementation also allows signals
36  * to terminate pg_usleep).  And there are platforms where not only does a
37  * signal not terminate the sleep, but it actually resets the timeout counter
38  * so that the sleep effectively starts over!  It is therefore rather hazardous
39  * to use this for long sleeps; a continuing stream of signal events could
40  * prevent the sleep from ever terminating.  Better practice for long sleeps
41  * is to use WaitLatch() with a timeout.
42  */
43 void
44 pg_usleep(long microsec)
45 {
46         if (microsec > 0)
47         {
48 #ifndef WIN32
49                 struct timeval delay;
50
51                 delay.tv_sec = microsec / 1000000L;
52                 delay.tv_usec = microsec % 1000000L;
53                 (void) select(0, NULL, NULL, NULL, &delay);
54 #else
55                 SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE);
56 #endif
57         }
58 }
59
60 #endif   /* defined(FRONTEND) || !defined(WIN32) */