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