--- rpl/src/instructions_s10.c 2011/06/10 11:35:13 1.33 +++ rpl/src/instructions_s10.c 2012/05/21 07:22:46 1.59 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.0.prerelease.0 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.8 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -45,12 +45,8 @@ instruction_spawn(struct_processus *s_et pthread_mutexattr_t attributs_mutex; - pthread_t thread_id; pthread_t thread_surveillance; - sigset_t oldset; - sigset_t set; - struct_descripteur_thread *s_argument_thread; struct_liste_chainee *l_element_courant; @@ -236,46 +232,6 @@ instruction_spawn(struct_processus *s_et } } - if (sigemptyset(&set) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - if (sigaddset(&set, SIGSTART) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - /* - * Le signal SIGFSTOP doit être traité ! - */ - - if (sigaddset(&set, SIGFSTOP) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - if (sigaddset(&set, SIGFABORT) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - if (sigaddset(&set, SIGURG) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - if (pthread_sigmask(SIG_BLOCK, &set, &oldset) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - if ((s_argument_thread = malloc(sizeof(struct_descripteur_thread))) == NULL) { (*s_etat_processus).erreur_systeme = d_es_processus; @@ -396,27 +352,29 @@ instruction_spawn(struct_processus *s_et 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 /* * Création de l'objet à retourner @@ -440,12 +398,6 @@ instruction_spawn(struct_processus *s_et // Lancement du thread fils - if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - (*s_argument_thread).s_nouvel_etat_processus = s_nouvel_etat_processus; (*s_argument_thread).s_etat_processus = s_etat_processus; @@ -460,12 +412,10 @@ instruction_spawn(struct_processus *s_et (*s_argument_thread).destruction_objet = d_faux; } - (*s_argument_thread).set = set; - (*s_argument_thread).oldset = oldset; (*s_argument_thread).thread_actif = d_faux; - if (pthread_create(&thread_id, &attributs, lancement_thread, - s_argument_thread) != 0) + if (pthread_create(&(*s_nouvel_etat_processus).tid, + &attributs, lancement_thread, s_argument_thread) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -476,6 +426,7 @@ instruction_spawn(struct_processus *s_et while((*s_argument_thread).thread_actif == d_faux) { + scrutation_interruptions(s_etat_processus); nanosleep(&attente, NULL); INCR_GRANULARITE(attente.tv_nsec); } @@ -499,36 +450,30 @@ instruction_spawn(struct_processus *s_et 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 - - // Attente de l'affectation de la grandeur processus.tid par le thread fils. - - if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } /* * On copie l'objet plutôt que le pointeur car cet objet peut être @@ -545,6 +490,7 @@ instruction_spawn(struct_processus *s_et if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) { + pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); (*s_etat_processus).erreur_systeme = d_es_processus; return; } @@ -606,6 +552,7 @@ instruction_spawn(struct_processus *s_et } } + scrutation_interruptions(s_etat_processus); l_element_courant = (*l_element_courant).suivant; } } while(drapeau == d_vrai); @@ -615,7 +562,6 @@ instruction_spawn(struct_processus *s_et .l_base_pile_processus), s_objet_systeme) == d_erreur) { pthread_mutex_unlock(&((*s_etat_processus).mutex)); - pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); return; } @@ -628,13 +574,11 @@ instruction_spawn(struct_processus *s_et if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), s_objet_resultat) == d_erreur) { - pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); return; } if (pthread_mutex_lock(&(*s_argument_thread).mutex) != 0) { - pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); (*s_etat_processus).erreur_systeme = d_es_processus; return; } @@ -644,7 +588,6 @@ instruction_spawn(struct_processus *s_et // Le thread n'existe plus. pthread_join((*s_argument_thread).tid, NULL); - pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); pthread_mutex_unlock(&(*s_argument_thread).mutex); (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -652,13 +595,6 @@ instruction_spawn(struct_processus *s_et if (pthread_mutex_unlock(&(*s_argument_thread).mutex) != 0) { - pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - if (pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)) != 0) - { (*s_etat_processus).erreur_systeme = d_es_processus; return; } @@ -680,20 +616,12 @@ instruction_spawn(struct_processus *s_et // Le fils peut être présent sans être en attente du signal de départ. - if (pthread_kill((*s_argument_thread).tid, SIGSTART) != 0) + if (envoi_signal_thread((*s_argument_thread).tid, rpl_sigstart) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; } - if (pthread_sigmask(SIG_SETMASK, &oldset, NULL) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - - sigpending(&set); - return; } @@ -778,10 +706,18 @@ instruction_sqlconnect(struct_processus if ((s_objet_resultat = parametres_sql(s_etat_processus, s_objet_argument)) == NULL) { + liberation(s_etat_processus, s_objet_resultat); liberation(s_etat_processus, s_objet_argument); return; } + if ((*s_etat_processus).erreur_execution == + d_ex_instruction_indisponible) + { + liberation(s_etat_processus, s_objet_resultat); + return; + } + if ((s_objet_systeme = copie_objet(s_etat_processus, s_objet_resultat, 'O')) == NULL) { @@ -1181,24 +1117,26 @@ instruction_smphrdecr(struct_processus * } # ifndef SEMAPHORES_NOMMES - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) # else - if (sem_post((*s_etat_processus).semaphore_fork) != 0) + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; } -# endif while(sem_wait((*((struct_semaphore *) (*s_objet_argument).objet)) .semaphore) == -1) { if (errno != EINTR) { +# ifndef SEMAPHORES_NOMMES + sem_post(&((*s_etat_processus).semaphore_fork)); +# else + sem_post((*s_etat_processus).semaphore_fork); +# endif + (*s_etat_processus).erreur_execution = d_ex_semaphore; if ((*s_etat_processus).profilage == d_vrai) @@ -1212,9 +1150,9 @@ instruction_smphrdecr(struct_processus * } # ifndef SEMAPHORES_NOMMES - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) # else - while(sem_wait((*s_etat_processus).semaphore_fork) == -1) + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) # endif { if (errno != EINTR) @@ -1263,9 +1201,16 @@ instruction_smphrdecr(struct_processus * void instruction_smphrtrydecr(struct_processus *s_etat_processus) { - struct_objet *s_objet_argument; + real8 partie_entiere; + + struct_objet *s_objet_argument_1; + struct_objet *s_objet_argument_2; struct_objet *s_objet_resultat; + struct timeval horodatage; + + struct timespec horodatage_absolu; + unsigned char *tampon; (*s_etat_processus).erreur_execution = d_ex; @@ -1283,7 +1228,8 @@ instruction_smphrtrydecr(struct_processu printf("(try to decremente semaphore)\n\n"); } - printf(" 1: %s\n", d_SPH); + printf(" 2: %s\n", d_SPH); + printf(" 1: %s, %s\n", d_INT, d_REL); printf("-> 1: %s\n", d_INT); return; } @@ -1295,21 +1241,70 @@ instruction_smphrtrydecr(struct_processu if (test_cfsf(s_etat_processus, 31) == d_vrai) { - if (empilement_pile_last(s_etat_processus, 1) == d_erreur) + if (empilement_pile_last(s_etat_processus, 2) == d_erreur) { return; } } if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), - &s_objet_argument) == d_erreur) + &s_objet_argument_1) == d_erreur) { (*s_etat_processus).erreur_execution = d_ex_manque_argument; return; } - if ((*s_objet_argument).type == SPH) + if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), + &s_objet_argument_2) == d_erreur) { + (*s_etat_processus).erreur_execution = d_ex_manque_argument; + return; + } + + if (((*s_objet_argument_2).type == SPH) && (((*s_objet_argument_1).type + == INT) || ((*s_objet_argument_1).type == REL))) + { + gettimeofday(&horodatage, NULL); + + if ((*s_objet_argument_1).type == INT) + { + if ((*((integer8 *) (*s_objet_argument_1).objet)) < 0) + { + (*s_etat_processus).erreur_execution = d_ex_argument_invalide; + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + return; + } + + horodatage.tv_sec += (*((integer8 *) (*s_objet_argument_1).objet)); + } + else + { + if ((*((real8 *) (*s_objet_argument_1).objet)) < 0) + { + (*s_etat_processus).erreur_execution = d_ex_argument_invalide; + + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); + return; + } + + partie_entiere = floor((*((real8 *) (*s_objet_argument_1).objet))); + horodatage.tv_sec += partie_entiere; + horodatage.tv_usec += ((suseconds_t) ((*((real8 *) + (*s_objet_argument_1).objet)) - partie_entiere)) * 1000000; + + if (horodatage.tv_usec > 1000000) + { + horodatage.tv_usec -= 1000000; + horodatage.tv_sec += 1; + } + } + + horodatage_absolu.tv_sec = horodatage.tv_sec; + horodatage_absolu.tv_nsec = horodatage.tv_usec * 1000; + if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1318,7 +1313,7 @@ instruction_smphrtrydecr(struct_processu if ((*s_etat_processus).profilage == d_vrai) { - if ((tampon = formateur(s_etat_processus, 0, s_objet_argument)) + if ((tampon = formateur(s_etat_processus, 0, s_objet_argument_2)) == NULL) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -1335,23 +1330,24 @@ instruction_smphrtrydecr(struct_processu } # ifndef SEMAPHORES_NOMMES - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) # else - if (sem_post((*s_etat_processus).semaphore_fork) != 0) + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { + if ((*s_etat_processus).profilage == d_vrai) + { + profilage(s_etat_processus, NULL); + } + (*s_etat_processus).erreur_systeme = d_es_processus; return; } -# endif - (*((integer8 *) (*s_objet_resultat).objet)) = 0; + (*((integer8 *) (*s_objet_resultat).objet)) = -1; - while(sem_trywait((*((struct_semaphore *) (*s_objet_argument).objet)) - .semaphore) == -1) + while(sem_timedwait((*((struct_semaphore *) (*s_objet_argument_2) + .objet)).semaphore, &horodatage_absolu) == -1) { switch(errno) { @@ -1369,27 +1365,28 @@ instruction_smphrtrydecr(struct_processu profilage(s_etat_processus, NULL); } - liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); return; } - case EAGAIN : + case ETIMEDOUT : { - (*((integer8 *) (*s_objet_resultat).objet)) = -1; + (*((integer8 *) (*s_objet_resultat).objet)) = 0; break; } } - if ((*((integer8 *) (*s_objet_resultat).objet)) != 0) + if ((*((integer8 *) (*s_objet_resultat).objet)) == 0) { break; } } # ifndef SEMAPHORES_NOMMES - while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) # else - while(sem_wait((*s_etat_processus).semaphore_fork) == -1) + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) # endif { if (errno != EINTR) @@ -1409,13 +1406,15 @@ instruction_smphrtrydecr(struct_processu profilage(s_etat_processus, NULL); } - liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); } else { (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; - liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_argument_1); + liberation(s_etat_processus, s_objet_argument_2); return; }