4153
|
1 /* |
|
2 |
|
3 Copyright (C) 2002 John W. Eaton |
|
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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_quit_h) |
|
24 #define octave_quit_h 1 |
|
25 |
|
26 #ifdef __cplusplus |
|
27 extern "C" { |
|
28 #endif |
|
29 |
|
30 // Include setjmp.h, not csetjmp since the latter might only define |
|
31 // the ANSI standard C interface. |
|
32 |
|
33 #include <setjmp.h> |
|
34 |
|
35 extern jmp_buf current_context; |
|
36 |
|
37 extern void octave_save_current_context (void *); |
|
38 |
|
39 #define octave_set_current_context setjmp (current_context) |
|
40 |
|
41 extern void octave_restore_current_context (void *); |
|
42 |
|
43 extern void octave_jump_to_enclosing_context (void) GCC_ATTR_NORETURN; |
|
44 |
|
45 extern void octave_save_signal_mask (void); |
|
46 |
|
47 extern void octave_restore_signal_mask (void); |
|
48 |
|
49 #if defined (USE_EXCEPTIONS_FOR_INTERRUPTS) |
|
50 |
|
51 #ifdef __cplusplus |
|
52 class |
|
53 octave_interrupt_exception |
|
54 { |
|
55 }; |
|
56 #endif |
|
57 |
|
58 extern int octave_interrupt_immediately; |
|
59 |
|
60 extern int octave_interrupt_state; |
|
61 |
|
62 extern void octave_throw_interrupt_exception (void) GCC_ATTR_NORETURN; |
|
63 |
|
64 #define OCTAVE_QUIT \ |
|
65 do \ |
|
66 { \ |
|
67 if (octave_interrupt_state) \ |
|
68 { \ |
|
69 octave_interrupt_state = 0; \ |
|
70 octave_throw_interrupt_exception (); \ |
|
71 } \ |
|
72 } \ |
|
73 while (0) |
|
74 |
|
75 #define OCTAVE_JUMP_TO_TOP_LEVEL \ |
|
76 do { octave_interrupt_state = 1; } while (0) |
|
77 |
|
78 #define OCTAVE_THROW_TO_TOP_LEVEL octave_throw_interrupt_exception () |
|
79 |
|
80 #define OCTAVE_TRY_WITH_INTERRUPTS try |
|
81 |
|
82 #define OCTAVE_CATCH_INTERRUPTS catch (octave_interrupt_exception) |
|
83 |
4155
|
84 #define INCREMENT_OCTAVE_INTERRUPT_IMMEDIATELY \ |
|
85 do { octave_interrupt_immediately++; } while (0) |
|
86 |
|
87 #define DECREMENT_OCTAVE_INTERRUPT_IMMEDIATELY \ |
|
88 do { octave_interrupt_immediately--; } while (0) |
|
89 |
|
90 #define SET_OCTAVE_INTERRUPT_IMMEDIATELY(x) \ |
|
91 do { octave_interrupt_immediately = x; } while (0) |
|
92 |
4153
|
93 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
|
94 do \ |
|
95 { \ |
|
96 jmp_buf saved_context; \ |
|
97 \ |
|
98 octave_save_current_context ((char *) saved_context); \ |
|
99 \ |
|
100 if (octave_set_current_context) \ |
|
101 { \ |
|
102 octave_restore_current_context ((char *) saved_context); \ |
|
103 OCTAVE_THROW_TO_TOP_LEVEL; \ |
|
104 } \ |
|
105 else \ |
|
106 { \ |
4155
|
107 INCREMENT_OCTAVE_INTERRUPT_IMMEDIATELY |
4153
|
108 |
|
109 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \ |
4155
|
110 DECREMENT_OCTAVE_INTERRUPT_IMMEDIATELY; \ |
4153
|
111 octave_restore_current_context ((char *) saved_context); \ |
|
112 } \ |
|
113 } \ |
|
114 while (0) |
|
115 |
|
116 #else |
|
117 |
|
118 #define OCTAVE_QUIT do { } while (0) |
|
119 |
|
120 #define OCTAVE_JUMP_TO_TOP_LEVEL octave_jump_to_enclosing_context () |
|
121 |
|
122 #define OCTAVE_THROW_TO_TOP_LEVEL OCTAVE_JUMP_TO_TOP_LEVEL |
|
123 |
|
124 #define OCTAVE_TRY_WITH_INTERRUPTS |
|
125 |
|
126 #define OCTAVE_CATCH_INTERRUPTS if (0) |
|
127 |
4155
|
128 #define INCREMENT_OCTAVE_INTERRUPT_IMMEDIATELY do { } while (0) |
|
129 |
|
130 #define DECREMENT_OCTAVE_INTERRUPT_IMMEDIATELY do { } while (0) |
|
131 |
4153
|
132 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE do { } while (0) |
|
133 |
|
134 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE do { } while (0) |
|
135 |
|
136 #endif |
|
137 |
|
138 #ifdef __cplusplus |
|
139 } |
|
140 #endif |
|
141 |
|
142 #endif |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |