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