Fix obsolete comment regarding FSM truncation.
[PostgreSQL.git] / src / port / pgsleep.c
blob693072cc15bb5c975153f02c1c39379a9b88d1c1
1 /*-------------------------------------------------------------------------
3 * pgsleep.c
4 * Portable delay handling.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
9 * $PostgreSQL$
11 *-------------------------------------------------------------------------
13 #include "c.h"
15 #include <unistd.h>
16 #include <sys/time.h>
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.
22 #if defined(FRONTEND) || !defined(WIN32)
25 * pg_usleep --- delay the specified number of microseconds.
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.
31 * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds.
33 void
34 pg_usleep(long microsec)
36 if (microsec > 0)
38 #ifndef WIN32
39 struct timeval delay;
41 delay.tv_sec = microsec / 1000000L;
42 delay.tv_usec = microsec % 1000000L;
43 (void) select(0, NULL, NULL, NULL, &delay);
44 #else
45 SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), FALSE);
46 #endif
50 #endif /* defined(FRONTEND) || !defined(WIN32) */