diff options
author | No author <no_author@ocaml.org> | 1995-06-15 16:08:54 +0000 |
---|---|---|
committer | No author <no_author@ocaml.org> | 1995-06-15 16:08:54 +0000 |
commit | 77b1c8b89fd8940a63b17c41eb37161e5d159831 (patch) | |
tree | 43dbfb3982d9166b717199cb8faa97bdce30add7 /byterun/signals.c | |
parent | ba79d4bd1f01a70b892c69f6a5e6e86714a023d6 (diff) | |
download | ocaml-unlabeled-1.2.2.tar.gz |
This commit was manufactured by cvs2svn to create branchunlabeled-1.2.2
'unlabeled-1.2.2'.
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/unlabeled-1.2.2@37 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'byterun/signals.c')
-rw-r--r-- | byterun/signals.c | 158 |
1 files changed, 0 insertions, 158 deletions
diff --git a/byterun/signals.c b/byterun/signals.c deleted file mode 100644 index a16a00c5a4..0000000000 --- a/byterun/signals.c +++ /dev/null @@ -1,158 +0,0 @@ -#include <signal.h> -#include "alloc.h" -#include "config.h" -#include "fail.h" -#include "interp.h" -#include "memory.h" -#include "misc.h" -#include "mlvalues.h" -#include "roots.h" -#include "signals.h" - -static Volatile int async_signal_mode = 0; -Volatile int pending_signal = 0; -value signal_handlers = 0; - -static void execute_signal(signal_number) - int signal_number; -{ - Assert (!async_signal_mode); - callback(Field(signal_handlers, signal_number), Val_int(signal_number)); -} - -void handle_signal(signal_number) - int signal_number; -{ -#ifndef BSD_SIGNALS - signal(signal_number, handle_signal); -#endif - if (async_signal_mode){ - leave_blocking_section (); - execute_signal(signal_number); - enter_blocking_section (); - }else{ - pending_signal = signal_number; - something_to_do = 1; - } -} - -void enter_blocking_section() -{ - int temp; - - while (1){ - Assert (!async_signal_mode); - /* If a signal arrives between the next two instructions, - it will be lost. */ - temp = pending_signal; pending_signal = 0; - if (temp) execute_signal(temp); - async_signal_mode = 1; - if (!pending_signal) break; - async_signal_mode = 0; - } -} - -/* This function may be called from outside a blocking section. */ -void leave_blocking_section() -{ - async_signal_mode = 0; -} - -#ifndef SIGABRT -#define SIGABRT 0 -#endif -#ifndef SIGALRM -#define SIGALRM 0 -#endif -#ifndef SIGFPE -#define SIGFPE 0 -#endif -#ifndef SIGHUP -#define SIGHUP 0 -#endif -#ifndef SIGILL -#define SIGILL 0 -#endif -#ifndef SIGINT -#define SIGINT 0 -#endif -#ifndef SIGKILL -#define SIGKILL 0 -#endif -#ifndef SIGPIPE -#define SIGPIPE 0 -#endif -#ifndef SIGQUIT -#define SIGQUIT 0 -#endif -#ifndef SIGSEGV -#define SIGSEGV 0 -#endif -#ifndef SIGTERM -#define SIGTERM 0 -#endif -#ifndef SIGUSR1 -#define SIGUSR1 0 -#endif -#ifndef SIGUSR2 -#define SIGUSR2 0 -#endif -#ifndef SIGCHLD -#define SIGCHLD 0 -#endif -#ifndef SIGCONT -#define SIGCONT 0 -#endif -#ifndef SIGSTOP -#define SIGSTOP 0 -#endif -#ifndef SIGTSTP -#define SIGTSTP 0 -#endif -#ifndef SIGTTIN -#define SIGTTIN 0 -#endif -#ifndef SIGTTOU -#define SIGTTOU 0 -#endif - -int posix_signals[] = { - SIGABRT, SIGALRM, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, - SIGQUIT, SIGSEGV, SIGTERM, SIGUSR1, SIGUSR2, SIGCHLD, SIGCONT, - SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU -}; - -value install_signal_handler(signal_number, action) /* ML */ - value signal_number, action; -{ - int sig = Int_val(signal_number); - if (sig < 0) { - sig = posix_signals[-sig-1]; - if (sig == 0) invalid_argument("Sys.signal: unavailable signal"); - } - switch(Tag_val(action)) { - case 0: /* Signal_default */ - signal(sig, SIG_DFL); - break; - case 1: /* Signal_ignore */ - signal(sig, SIG_IGN); - break; - case 2: /* Signal_handle */ - if (signal_handlers == 0) { - int i; - Push_roots(r, 1); - r[0] = action; - signal_handlers = alloc_tuple(32); - action = r[0]; - Pop_roots(); - for (i = 0; i < 32; i++) Field(signal_handlers, i) = Val_int(0); - register_global_root(&signal_handlers); - } - modify(&Field(signal_handlers, sig), Field(action, 0)); - signal(sig, handle_signal); - break; - default: - Assert(0); - } - return Val_unit; -} |