dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / efcode / engine / alarm.c
blobc9d4550a9d3a6172bb5546a342922a9e0d8e2ad3
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <unistd.h>
34 #include <fcode/private.h>
37 * 'user-abort' Fcode
39 void
40 user_abort(fcode_env_t *env)
42 forth_abort(env, "user-abort called");
45 static fstack_t alarm_xt;
46 static fstack_t alarm_ms;
47 static fcode_env_t *alarm_env;
49 static void
50 catch_alarm(int signo)
52 fcode_env_t *env = alarm_env;
54 if (env && alarm_xt && alarm_ms) {
55 PUSH(DS, alarm_xt);
56 execute(env);
57 signal(SIGALRM, catch_alarm);
58 alarm((alarm_ms + 999)/1000);
63 * 'alarm' Fcode
65 void
66 do_alarm(fcode_env_t *env)
68 fstack_t ms, xt;
70 CHECK_DEPTH(env, 2, "alarm");
71 ms = POP(DS);
72 xt = POP(DS);
73 if (ms == 0) {
74 alarm(0);
75 signal(SIGALRM, SIG_DFL);
76 alarm_xt = 0;
77 alarm_ms = 0;
78 alarm_env = 0;
79 } else {
80 signal(SIGALRM, catch_alarm);
81 alarm_xt = xt;
82 alarm_ms = ms;
83 alarm_env = env;
84 alarm((ms + 999)/1000);
88 #pragma init(_init)
90 static void
91 _init(void)
93 fcode_env_t *env = initial_env;
95 ASSERT(env);
96 NOTICE;
98 P1275(0x213, 0, "alarm", do_alarm);
100 P1275(0x219, 0, "user-abort", user_abort);