]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_partikle/tests/test_long_jump.c
New way of handling long jumps
[frescor/fosa.git] / src_partikle / tests / test_long_jump.c
1
2 #include <fosa_long_jump.h>
3 #include <fosa_threads_and_signals.h>
4 #include <stdio.h>
5
6 void f1 (void)
7 {
8         fosa_long_jump_context_t ctx;
9         fosa_signal_t sig;
10         fosa_thread_id_t th;
11         int jmp;
12         fosa_signal_info_t ctx_info;
13         
14         
15         printf (">>> save context\n\n");
16         if (fosa_long_jump_save_context (&ctx))
17                 perror ("fosa_long_jump_save_context");
18         
19         printf (">>> check jump performed\n\n");
20         if (fosa_long_jump_was_performed ((const fosa_long_jump_context_t *) &ctx, &jmp))
21                 perror ("fosa_long_jump_was_performed");
22         
23         if (jmp) {
24                 printf ("\t <<<< JUMPED\n\n");
25                 exit (10);
26         }
27
28         printf (">>> install handler\n\n");
29         if (fosa_long_jump_install_handler (&sig, &th))
30                 perror ("fosa_long_jump_install_handler()");
31                 
32         printf ("\t signal=%d, thread=0x%x (self=0x%x)\n",  sig, (unsigned int) th, (unsigned int) fosa_thread_self());
33         
34         printf (">>> trigger a long jump using a signal\n\n");
35         ctx_info.sival_ptr = &ctx;
36         if (fosa_signal_queue (sig, ctx_info, th))
37                 perror ("fosa_signal_queue");
38         
39 }
40
41
42 int main (void)
43 {
44         f1 ();
45         return 0;
46 }
47