diff options
Diffstat (limited to 'include/litmus.h')
-rw-r--r-- | include/litmus.h | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/include/litmus.h b/include/litmus.h index c284870..ca8328f 100644 --- a/include/litmus.h +++ b/include/litmus.h | |||
@@ -144,6 +144,9 @@ int null_call(cycles_t *timestamp); | |||
144 | */ | 144 | */ |
145 | struct control_page* get_ctrl_page(void); | 145 | struct control_page* get_ctrl_page(void); |
146 | 146 | ||
147 | |||
148 | /* Litmus signal handling */ | ||
149 | |||
147 | typedef struct litmus_sigjmp | 150 | typedef struct litmus_sigjmp |
148 | { | 151 | { |
149 | sigjmp_buf env; | 152 | sigjmp_buf env; |
@@ -156,12 +159,26 @@ litmus_sigjmp_t* pop_sigjmp(void); | |||
156 | typedef void (*litmus_sig_handler_t)(int); | 159 | typedef void (*litmus_sig_handler_t)(int); |
157 | typedef void (*litmus_sig_actions_t)(int, siginfo_t *, void *); | 160 | typedef void (*litmus_sig_actions_t)(int, siginfo_t *, void *); |
158 | 161 | ||
162 | /* ignore specified signals. all signals raised while ignored are dropped */ | ||
159 | void ignore_litmus_signals(unsigned long litmus_sig_mask); | 163 | void ignore_litmus_signals(unsigned long litmus_sig_mask); |
164 | |||
165 | /* register a handler for the given set of litmus signals */ | ||
160 | void activate_litmus_signals(unsigned long litmus_sig_mask, | 166 | void activate_litmus_signals(unsigned long litmus_sig_mask, |
161 | litmus_sig_handler_t handler); | 167 | litmus_sig_handler_t handler); |
168 | |||
169 | /* register an action signal handler for a given set of signals */ | ||
162 | void activate_litmus_signal_actions(unsigned long litmus_sig_mask, | 170 | void activate_litmus_signal_actions(unsigned long litmus_sig_mask, |
163 | litmus_sig_actions_t handler); | 171 | litmus_sig_actions_t handler); |
172 | |||
173 | /* Block a given set of litmus signals. Any signals raised while blocked | ||
174 | * are queued and delivered after unblocking. Call ignore_litmus_signals() | ||
175 | * before unblocking if you wish to discard these. Blocking may be | ||
176 | * useful to protect COTS code in Litmus that may not be able to deal | ||
177 | * with exception-raising signals. | ||
178 | */ | ||
164 | void block_litmus_signals(unsigned long litmus_sig_mask); | 179 | void block_litmus_signals(unsigned long litmus_sig_mask); |
180 | |||
181 | /* Unblock a given set of litmus signals. */ | ||
165 | void unblock_litmus_signals(unsigned long litmus_sig_mask); | 182 | void unblock_litmus_signals(unsigned long litmus_sig_mask); |
166 | 183 | ||
167 | #define SIG_BUDGET_MASK 0x00000001 | 184 | #define SIG_BUDGET_MASK 0x00000001 |
@@ -169,7 +186,9 @@ void unblock_litmus_signals(unsigned long litmus_sig_mask); | |||
169 | 186 | ||
170 | #define ALL_LITMUS_SIG_MASKS (SIG_BUDGET_MASK) | 187 | #define ALL_LITMUS_SIG_MASKS (SIG_BUDGET_MASK) |
171 | 188 | ||
172 | 189 | /* Try/Catch structures useful for implementing abortable jobs. | |
190 | * Should only be used in legitimate cases. ;) | ||
191 | */ | ||
173 | #define LITMUS_TRY \ | 192 | #define LITMUS_TRY \ |
174 | do { \ | 193 | do { \ |
175 | int sigsetjmp_ret_##__FUNCTION__##__LINE__; \ | 194 | int sigsetjmp_ret_##__FUNCTION__##__LINE__; \ |
@@ -186,6 +205,10 @@ do { \ | |||
186 | } /* end if-else-if chain */ \ | 205 | } /* end if-else-if chain */ \ |
187 | } while(0); /* end do from 'LITMUS_TRY' */ | 206 | } while(0); /* end do from 'LITMUS_TRY' */ |
188 | 207 | ||
208 | /* Calls siglongjmp(signum). Use with TRY/CATCH. | ||
209 | * Example: | ||
210 | * activate_litmus_signals(SIG_BUDGET_MASK, longjmp_on_litmus_signal); | ||
211 | */ | ||
189 | void longjmp_on_litmus_signal(int signum); | 212 | void longjmp_on_litmus_signal(int signum); |
190 | 213 | ||
191 | #ifdef __cplusplus | 214 | #ifdef __cplusplus |
@@ -223,20 +246,20 @@ namespace litmus | |||
223 | }; | 246 | }; |
224 | 247 | ||
225 | /* Must compile your program with "non-call-exception". */ | 248 | /* Must compile your program with "non-call-exception". */ |
226 | static void throw_on_litmus_signal(int signum) __used__ | 249 | static __attribute__((used)) |
250 | void throw_on_litmus_signal(int signum) | ||
227 | { | 251 | { |
228 | printf("WE GET SIGNAL! %d\n", signum); | ||
229 | /* We have to unblock the received signal to get more in the future | 252 | /* We have to unblock the received signal to get more in the future |
230 | * because we are not calling siglongjmp(), which normally restores | 253 | * because we are not calling siglongjmp(), which normally restores |
231 | * the mask for us. | 254 | * the mask for us. |
232 | */ | 255 | */ |
233 | switch(signum) | 256 | if (SIG_BUDGET == signum) { |
234 | { | ||
235 | case SIG_BUDGET: | ||
236 | unblock_litmus_signals(SIG_BUDGET_MASK); | 257 | unblock_litmus_signals(SIG_BUDGET_MASK); |
237 | throw sigbudget(); | 258 | throw sigbudget(); |
238 | default: | 259 | } |
239 | ; /* silently ignore */ | 260 | /* else if (...) */ |
261 | else { | ||
262 | /* silently ignore */ | ||
240 | } | 263 | } |
241 | } | 264 | } |
242 | 265 | ||