4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
26 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/sysmacros.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/signal.h>
40 #include <sys/cmn_err.h>
41 #include <sys/debug.h>
44 sigalarm2proc(void *arg
)
48 mutex_enter(&p
->p_lock
);
50 sigtoproc(p
, NULL
, SIGALRM
);
51 mutex_exit(&p
->p_lock
);
57 proc_t
*p
= ttoproc(curthread
);
61 clock_t delta
= (uint_t
)deltat
;
64 * We must single-thread this code relative to other
65 * lwps in the same process also performing an alarm().
66 * The mutex dance in the while loop is necessary because
67 * we cannot call untimeout() while holding a lock that
68 * is grabbed by the timeout function, sigalarm2proc().
69 * We can, however, hold p->p_lock across realtime_timeout().
71 mutex_enter(&p
->p_lock
);
72 while ((tmp_id
= p
->p_alarmid
) != 0) {
74 mutex_exit(&p
->p_lock
);
75 del
= untimeout(tmp_id
);
76 mutex_enter(&p
->p_lock
);
82 ret
= (del
+ hz
- 1) / hz
; /* convert to seconds */
85 * Our implementation defined limit for alarm is
86 * LONG_MAX / hz. Anything larger gets truncated
87 * to that limit. If delta is negative we can
88 * assume a wrap has occurred so peg delta in
89 * that case too. 64 bit platforms have higher limit.
91 if (delta
> (LONG_MAX
/ hz
) || delta
< 0)
92 delta
= LONG_MAX
/ hz
;
95 p
->p_alarmid
= realtime_timeout(sigalarm2proc
, p
, delta
* hz
);
96 mutex_exit(&p
->p_lock
);