Mercurial > hg > octave-nkf
annotate libinterp/corefcn/sighandlers.h @ 19827:e68267373191
chop.m: Calculate deflate as 1./inflate (bug #43734).
chop.m: Calculate deflate as 1./inflate (bug #43734).
author | Rik <rik@octave.org> |
---|---|
date | Sat, 24 Jan 2015 22:27:12 -0800 |
parents | 1adf3710bb68 |
children | 4197fc428c7d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17569
diff
changeset
|
3 Copyright (C) 1993-2013 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
2939 | 23 /* |
24 | |
25 The signal blocking macros defined below were adapted from similar | |
26 functions from GNU Bash, the Bourne Again SHell, copyright (C) 1994 | |
27 Free Software Foundation, Inc. | |
28 | |
29 */ | |
30 | |
834 | 31 // This file should always be included after config.h! |
32 | |
383 | 33 #if !defined (octave_sighandlers_h) |
34 #define octave_sighandlers_h 1 | |
1 | 35 |
3566 | 36 // Include signal.h, not csignal since the latter might only define |
37 // the ANSI standard C signal interface. | |
38 | |
39 #include <signal.h> | |
2209 | 40 |
41 #include "syswait.h" | |
3546 | 42 #include "siglist.h" |
2209 | 43 |
5142 | 44 #include "base-list.h" |
3566 | 45 |
10246 | 46 typedef void sig_handler (int); |
290 | 47 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
48 // FIXME: the data should probably be private... |
2554 | 49 |
2705 | 50 struct |
51 octave_interrupt_handler | |
52 { | |
53 #ifdef SIGINT | |
54 sig_handler *int_handler; | |
55 #endif | |
56 | |
57 #ifdef SIGBREAK | |
58 sig_handler *brk_handler; | |
59 #endif | |
60 }; | |
2554 | 61 |
1 | 62 // Nonzero means we have already printed a message for this series of |
63 // SIGPIPES. We assume that the writer will eventually give up. | |
64 extern int pipe_handler_error_count; | |
65 | |
3018 | 66 // TRUE means we can be interrupted. |
6972 | 67 extern OCTINTERP_API bool can_interrupt; |
1 | 68 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
69 extern OCTINTERP_API |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
70 sig_handler *octave_set_signal_handler (int, sig_handler *, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
71 bool restart_syscalls = true); |
1443 | 72 |
6109 | 73 extern OCTINTERP_API void install_signal_handlers (void); |
1 | 74 |
6109 | 75 extern OCTINTERP_API void octave_signal_handler (void); |
5142 | 76 |
6109 | 77 extern OCTINTERP_API octave_interrupt_handler octave_catch_interrupts (void); |
2554 | 78 |
6109 | 79 extern OCTINTERP_API octave_interrupt_handler octave_ignore_interrupts (void); |
2554 | 80 |
6109 | 81 extern OCTINTERP_API octave_interrupt_handler |
5770 | 82 octave_set_interrupt_handler (const volatile octave_interrupt_handler&, |
10313 | 83 bool restart_syscalls = true); |
1651 | 84 |
17958
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
85 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
86 extern OCTINTERP_API void w32_raise_sigint (void); |
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
87 #endif |
1adf3710bb68
Working CTRL-C handling implementation for Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
17787
diff
changeset
|
88 |
2214 | 89 // extern void ignore_sigchld (void); |
90 | |
2209 | 91 // Maybe this should be in a separate file? |
92 | |
93 class | |
6109 | 94 OCTINTERP_API |
2209 | 95 octave_child |
96 { | |
97 public: | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
98 |
5142 | 99 // Do whatever to handle event for child with PID (might not |
100 // actually be dead, could just be stopped). Return true if | |
101 // the list element corresponding to PID should be removed from | |
102 // list. This function should not call any functions that modify | |
103 // the octave_child_list. | |
2209 | 104 |
5142 | 105 typedef bool (*child_event_handler) (pid_t, int); |
106 | |
107 octave_child (pid_t id = -1, child_event_handler f = 0) | |
108 : pid (id), handler (f), have_status (0), status (0) { } | |
2209 | 109 |
110 octave_child (const octave_child& oc) | |
5142 | 111 : pid (oc.pid), handler (oc.handler), |
112 have_status (oc.have_status), status (oc.status) { } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11525
diff
changeset
|
113 |
2209 | 114 octave_child& operator = (const octave_child& oc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
115 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
116 if (&oc != this) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
117 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
118 pid = oc.pid; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
119 handler = oc.handler; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
120 have_status = oc.have_status; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
121 status = oc.status; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
122 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
123 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17778
diff
changeset
|
124 } |
2209 | 125 |
126 ~octave_child (void) { } | |
127 | |
128 // The process id of this child. | |
129 pid_t pid; | |
130 | |
5142 | 131 // The function we call if an event happens for this child. |
132 child_event_handler handler; | |
133 | |
134 // Nonzero if this child has stopped or terminated. | |
135 sig_atomic_t have_status; | |
136 | |
137 // The status of this child; 0 if running, otherwise a status value | |
138 // from waitpid. | |
139 int status; | |
2209 | 140 }; |
141 | |
142 class | |
6109 | 143 OCTINTERP_API |
2209 | 144 octave_child_list |
145 { | |
146 protected: | |
147 | |
5142 | 148 octave_child_list (void) { } |
149 | |
150 class octave_child_list_rep : public octave_base_list<octave_child> | |
151 { | |
152 public: | |
153 | |
154 void insert (pid_t pid, octave_child::child_event_handler f); | |
155 | |
156 void reap (void); | |
157 | |
158 bool wait (void); | |
159 }; | |
2209 | 160 |
161 public: | |
162 | |
5142 | 163 ~octave_child_list (void) { } |
164 | |
165 static void insert (pid_t pid, octave_child::child_event_handler f); | |
2209 | 166 |
5142 | 167 static void reap (void); |
2926 | 168 |
5142 | 169 static bool wait (void); |
2209 | 170 |
2214 | 171 static void remove (pid_t pid); |
172 | |
2209 | 173 private: |
174 | |
5142 | 175 static bool instance_ok (void); |
2209 | 176 |
5142 | 177 static octave_child_list_rep *instance; |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
178 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
179 static void cleanup_instance (void) { delete instance; instance = 0; } |
2209 | 180 }; |
181 | |
15595
6e780fb15c14
Make Vdebug_on_interrupt not be static
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
182 // TRUE means we should try to enter the debugger on SIGINT. |
6e780fb15c14
Make Vdebug_on_interrupt not be static
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
183 extern OCTINTERP_API bool Vdebug_on_interrupt; |
6e780fb15c14
Make Vdebug_on_interrupt not be static
Max Brister <max@2bass.com>
parents:
15195
diff
changeset
|
184 |
1 | 185 #endif |