00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_quit_h)
00024 #define octave_quit_h 1
00025
00026 #ifdef __cplusplus
00027 #include <new>
00028 extern "C" {
00029 #endif
00030
00031 #include <stdio.h>
00032
00033 #include <signal.h>
00034 #include <setjmp.h>
00035
00036 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
00037
00038 #include <windows.h>
00039 #undef min
00040 #undef max
00041
00042 CRUFT_API extern void w32_sigint_init (void);
00043 CRUFT_API extern void w32_raise_final (void);
00044 CRUFT_API extern void w32_raise (int sig);
00045 CRUFT_API extern int w32_in_main_thread (void);
00046
00047 #endif
00048
00049 #if defined (OCTAVE_HAVE_SIG_JUMP)
00050
00051 typedef sigjmp_buf octave_jmp_buf;
00052
00053 #define octave_set_current_context sigsetjmp (current_context, 1)
00054
00055 #else
00056
00057 typedef jmp_buf octave_jmp_buf;
00058
00059 #define octave_set_current_context setjmp (current_context)
00060
00061 #endif
00062
00063 CRUFT_API extern octave_jmp_buf current_context;
00064
00065 CRUFT_API extern void octave_save_current_context (void *);
00066
00067 CRUFT_API extern void octave_restore_current_context (void *);
00068
00069 CRUFT_API extern void octave_jump_to_enclosing_context (void) GCC_ATTR_NORETURN;
00070
00071 CRUFT_API extern void octave_save_signal_mask (void);
00072
00073 CRUFT_API extern void octave_restore_signal_mask (void);
00074
00075 #ifdef __cplusplus
00076 class
00077 octave_interrupt_exception
00078 {
00079 };
00080 #endif
00081
00082 CRUFT_API extern sig_atomic_t octave_interrupt_immediately;
00083
00084
00085
00086
00087
00088
00089 CRUFT_API extern sig_atomic_t octave_interrupt_state;
00090
00091 CRUFT_API extern sig_atomic_t octave_allocation_error;
00092
00093 CRUFT_API extern sig_atomic_t octave_signal_caught;
00094
00095 CRUFT_API extern void octave_handle_signal (void);
00096
00097 CRUFT_API extern void octave_throw_interrupt_exception (void) GCC_ATTR_NORETURN;
00098
00099 CRUFT_API extern void octave_throw_bad_alloc (void) GCC_ATTR_NORETURN;
00100
00101 #define OCTAVE_QUIT \
00102 do \
00103 { \
00104 if (octave_signal_caught) \
00105 { \
00106 octave_signal_caught = 0; \
00107 octave_handle_signal (); \
00108 } \
00109 } \
00110 while (0)
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
00129 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1; \
00130 octave_throw_interrupt_exception (); \
00131 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2
00132
00133 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_1 \
00134 do \
00135 { \
00136 octave_jmp_buf saved_context; \
00137 \
00138 octave_save_current_context (saved_context); \
00139 \
00140 if (octave_set_current_context) \
00141 { \
00142 octave_restore_current_context (saved_context)
00143
00144 #define BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE_2 \
00145 } \
00146 else \
00147 { \
00148 octave_interrupt_immediately++
00149
00150 #define END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE \
00151 octave_interrupt_immediately--; \
00152 octave_restore_current_context (saved_context); \
00153 } \
00154 } \
00155 while (0)
00156
00157 #ifdef __cplusplus
00158
00159 #define BEGIN_INTERRUPT_WITH_EXCEPTIONS \
00160 sig_atomic_t saved_octave_interrupt_immediately = octave_interrupt_immediately; \
00161 \
00162 try \
00163 { \
00164 octave_interrupt_immediately = 0;
00165
00166 #define END_INTERRUPT_WITH_EXCEPTIONS \
00167 } \
00168 catch (octave_interrupt_exception) \
00169 { \
00170 octave_interrupt_immediately = saved_octave_interrupt_immediately; \
00171 octave_jump_to_enclosing_context (); \
00172 } \
00173 catch (std::bad_alloc) \
00174 { \
00175 octave_interrupt_immediately = saved_octave_interrupt_immediately; \
00176 octave_allocation_error = 1; \
00177 octave_jump_to_enclosing_context (); \
00178 } \
00179 \
00180 octave_interrupt_immediately = saved_octave_interrupt_immediately
00181 #endif
00182
00183 #ifdef __cplusplus
00184 }
00185
00186
00187
00188
00189 extern CRUFT_API void (*octave_signal_hook) (void);
00190 extern CRUFT_API void (*octave_interrupt_hook) (void);
00191 extern CRUFT_API void (*octave_bad_alloc_hook) (void);
00192
00193 #endif
00194
00195 #endif
00196
00197
00198
00199
00200
00201