--- rpl/src/instructions_d5.c 2011/09/20 08:56:23 1.71 +++ rpl/src/instructions_d5.c 2012/08/22 10:47:15 1.90 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.3 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.10 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -817,7 +817,6 @@ instruction_detach(struct_processus *s_e int pipe_initialisation_segment_signaux[2]; logical1 drapeau; - logical1 variable_partagee; pid_t ppid; pid_t pid_final; @@ -856,6 +855,8 @@ instruction_detach(struct_processus *s_e unsigned long i; + volatile logical1 variable_partagee; + (*s_etat_processus).erreur_execution = d_ex; attente.tv_sec = 0; @@ -1231,28 +1232,30 @@ instruction_detach(struct_processus *s_e return; } -# ifndef OS2 -# ifndef Cygwin +# ifdef SCHED_OTHER if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } +# endif +# ifdef PTHREAD_EXPLICIT_SCHED if (pthread_attr_setinheritsched(&attributs, PTHREAD_EXPLICIT_SCHED) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } +# endif +# ifdef PTHREAD_SCOPE_SYSTEM if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } # endif -# endif (*s_argument_thread).s_etat_processus = s_etat_processus; @@ -1277,6 +1280,7 @@ instruction_detach(struct_processus *s_e liberation_queue_signaux(s_etat_processus); creation_queue_signaux(s_etat_processus); + routine_recursive = 0; (*s_etat_processus).pointeur_signal_lecture = 0; (*s_etat_processus).pointeur_signal_ecriture = 0; @@ -1363,13 +1367,6 @@ instruction_detach(struct_processus *s_e l_element_courant = (*s_etat_processus).liste_mutexes; while(l_element_courant != NULL) { - pthread_mutex_trylock(&((*((struct_mutex *) (*(*l_element_courant) - .donnee).objet)).mutex)); - pthread_mutex_unlock(&((*((struct_mutex *) (*(*l_element_courant) - .donnee).objet)).mutex)); - pthread_mutex_destroy(&((*((struct_mutex *) (*(*l_element_courant) - .donnee).objet)).mutex)); - liberation(s_etat_processus, (*l_element_courant).donnee); l_element_suivant = (*l_element_courant).suivant; free(l_element_courant); @@ -1951,6 +1948,18 @@ instruction_detach(struct_processus *s_e if ((*s_etat_processus).erreur_systeme == d_es) { + // Évite le warning variable s_copie might be clobbered by + // longjmp or vfork + struct_objet **s; + + if ((s = malloc(sizeof(struct_objet *))) == NULL) + { + (*s_etat_processus).erreur_execution = d_es_allocation_memoire; + return; + } + + (*s) = s_copie; + if (setjmp(contexte_processus) == 0) { if (variable_partagee == d_faux) @@ -1984,7 +1993,7 @@ instruction_detach(struct_processus *s_e } else { - if (evaluation(s_etat_processus, s_copie, 'E') == d_erreur) + if (evaluation(s_etat_processus, (*s), 'E') == d_erreur) { if (((*s_etat_processus).erreur_execution == d_ex) && ((*s_etat_processus).erreur_systeme == d_es)) @@ -1995,7 +2004,9 @@ instruction_detach(struct_processus *s_e } else { - if ((*s_etat_processus).at_exit != NULL) + if (((*s_etat_processus).var_volatile_alarme == 0) + && ((*s_etat_processus).arret_depuis_abort == 0) + && ((*s_etat_processus).at_exit != NULL)) { (*s_etat_processus).var_volatile_requete_arret = 0; @@ -2009,9 +2020,11 @@ instruction_detach(struct_processus *s_e } } - liberation(s_etat_processus, s_copie); + liberation(s_etat_processus, (*s)); } } + + free(s); } liberation(s_etat_processus, (*s_etat_processus).at_exit); @@ -2020,13 +2033,6 @@ instruction_detach(struct_processus *s_e l_element_courant = (*s_etat_processus).liste_mutexes; while(l_element_courant != NULL) { - pthread_mutex_trylock(&((*((struct_mutex *) - (*(*l_element_courant).donnee).objet)).mutex)); - pthread_mutex_unlock(&((*((struct_mutex *) - (*(*l_element_courant).donnee).objet)).mutex)); - pthread_mutex_destroy(&((*((struct_mutex *) - (*(*l_element_courant).donnee).objet)).mutex)); - liberation(s_etat_processus, (*l_element_courant).donnee); l_element_suivant = (*l_element_courant).suivant; free(l_element_courant); @@ -2768,8 +2774,14 @@ instruction_detach(struct_processus *s_e pthread_mutex_destroy(&((*s_etat_processus).mutex_allocation)); pthread_mutex_destroy(&((*s_etat_processus).protection_liste_mutexes)); +# ifndef SEMAPHORES_NOMMES sem_post(&((*s_etat_processus).semaphore_fork)); sem_destroy(&((*s_etat_processus).semaphore_fork)); +# else + sem_post((*s_etat_processus).semaphore_fork); + sem_destroy3((*s_etat_processus).semaphore_fork, getpid(), + pthread_self(), SEM_FORK); +# endif free((*s_etat_processus).localisation); free(s_argument_thread);