]> rtime.felk.cvut.cz Git - frescor/fosa.git/commitdiff
FOSA-PaRTiKle: conditional compilation to free used signals in long jumps
authoriripoll <iripoll@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Wed, 27 Feb 2008 11:59:05 +0000 (11:59 +0000)
committeriripoll <iripoll@35b4ef3e-fd22-0410-ab77-dab3279adceb>
Wed, 27 Feb 2008 11:59:05 +0000 (11:59 +0000)
git-svn-id: http://www.frescor.org/private/svn/frescor/fosa/trunk@1029 35b4ef3e-fd22-0410-ab77-dab3279adceb

src_partikle/fosa_long_jump.c

index 6ad54075c1bc47a3871fc1f6099ba33510dd9549..446207474bac4d68b022a5d57c8ac6ef88f99ad3 100644 (file)
@@ -75,6 +75,7 @@ enum {
 
 int jmp_used_signals [LONGJMP_NSIG] = {[0 ... (LONGJMP_NSIG - 1)] = 0};
 
+
 int fosa_long_jump_save_context
    (fosa_long_jump_context_t * context)
 {
@@ -86,12 +87,15 @@ int fosa_long_jump_save_context
   context -> jmp_hasexecuted  = false;
 
   if (setjmp (context -> jmp_context) == LONGJMP_MAGIC) {
-    context -> jmp_hasexecuted = true;
+#ifndef CONFIG_LONGJUMP_FREE_SIGNALS
     pthread_sigmask (SIG_SETMASK, &(context -> jmp_sigmask), NULL);
+#endif 
+    context -> jmp_hasexecuted = true;
   }
   return 0;
 }
 
+
 int fosa_long_jump_was_performed
     (const fosa_long_jump_context_t * context, int * jumped)
 {
@@ -102,13 +106,32 @@ int fosa_long_jump_was_performed
   return 0;
 }
 
+
 void jmp_handler (int signo, siginfo_t *info, void *context)
 {
   fosa_long_jump_context_t *jmp_info = (fosa_long_jump_context_t *) info -> si_value.sival_ptr;
+  sigset_t set;
+
+#ifdef CONFIG_LONGJUMP_FREE_SIGNALS
+  // Restore the signal mask beofre the context save
+  pthread_sigmask (SIG_SETMASK, &(context -> jmp_sigmask), NULL);
+
+  // Free this signal
+  sigemptyset (&set);
+  sigaddset (&set, signo);
+  pthread_sigmask (SIG_BLOCK, &sigmask, NULL);
+
+  pthread_mutex_lock ();
+  jmp_used_signals [signo] = 0;
+  pthread_mutex_unlock ();
+#endif
+
+  // Restore the saved context
   longjmp (jmp_info -> jmp_context, LONGJMP_MAGIC);
   return;
 }
 
+
 int fosa_long_jump_install_handler
     (fosa_signal_t *signal, fosa_thread_id_t *handler)
 {
@@ -141,5 +164,4 @@ int fosa_long_jump_install_handler
   return 0;
 }
 
-
 #endif /* CONFIG_LONGJUMP */