xref: /titanic_52/usr/src/cmd/sendmail/db/os/os_sleep.c (revision 269e59f9a28bf47e0f463e64fc5af4a408b73b21)
1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 1997, 1998
5  *	Sleepycat Software.  All rights reserved.
6  */
7 
8 #include "config.h"
9 
10 #ifndef lint
11 static const char sccsid[] = "@(#)os_sleep.c	10.12 (Sleepycat) 10/12/98";
12 #endif /* not lint */
13 
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
16 #ifdef HAVE_SYS_TIME_H
17 #include <sys/time.h>
18 #endif
19 #ifdef HAVE_SYS_SELECT_H
20 #include <sys/select.h>
21 #endif
22 
23 #include <errno.h>
24 #ifndef HAVE_SYS_TIME_H
25 #include <time.h>
26 #endif
27 #include <unistd.h>
28 #endif
29 
30 #include "db_int.h"
31 #include "os_jump.h"
32 
33 /*
34  * __os_sleep --
35  *	Yield the processor for a period of time.
36  *
37  * PUBLIC: int __os_sleep __P((u_long, u_long));
38  */
39 int
40 __os_sleep(secs, usecs)
41 	u_long secs, usecs;		/* Seconds and microseconds. */
42 {
43 	struct timeval t;
44 
45 	/* Don't require that the values be normalized. */
46 	for (; usecs >= 1000000; ++secs, usecs -= 1000000)
47 		;
48 
49 	if (__db_jump.j_sleep != NULL)
50 		return (__db_jump.j_sleep(secs, usecs));
51 
52 	/*
53 	 * It's important that we yield the processor here so that other
54 	 * processes or threads are permitted to run.
55 	 */
56 	t.tv_sec = secs;
57 	t.tv_usec = usecs;
58 	return (select(0, NULL, NULL, NULL, &t) == -1 ? errno : 0);
59 }
60