--- rpl/src/instructions_s10.c 2011/09/20 08:56:24 1.46 +++ rpl/src/instructions_s10.c 2012/12/18 13:19:38 1.65 @@ -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.12 + Copyright (C) 1989-2012 Dr. BERTRAND Joël This file is part of RPL/2. @@ -45,7 +45,6 @@ instruction_spawn(struct_processus *s_et pthread_mutexattr_t attributs_mutex; - pthread_t thread_id; pthread_t thread_surveillance; struct_descripteur_thread *s_argument_thread; @@ -131,26 +130,12 @@ instruction_spawn(struct_processus *s_et { if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL) { - if (pthread_mutex_lock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - if (recherche_variable_partagee(s_etat_processus, (*(*s_etat_processus).pointeur_variable_courante).nom, (*(*s_etat_processus).pointeur_variable_courante) .variable_partagee, (*(*s_etat_processus) - .pointeur_variable_courante).origine) == d_faux) + .pointeur_variable_courante).origine) == NULL) { - if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) - { - (*s_etat_processus).erreur_systeme = d_es_processus; - return; - } - liberation(s_etat_processus, s_objet); (*s_etat_processus).erreur_systeme = d_es; @@ -159,16 +144,14 @@ instruction_spawn(struct_processus *s_et return; } - if (((*(*(*s_etat_processus).s_liste_variables_partagees) - .table[(*(*s_etat_processus) - .s_liste_variables_partagees).position_variable].objet) - .type != RPN) && ((*(*(*s_etat_processus) - .s_liste_variables_partagees).table - [(*(*s_etat_processus).s_liste_variables_partagees) - .position_variable].objet).type != ADR)) + if (((*(*(*s_etat_processus) + .pointeur_variable_partagee_courante).objet).type + != RPN) && ((*(*(*s_etat_processus) + .pointeur_variable_partagee_courante).objet).type + != ADR)) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -183,12 +166,11 @@ instruction_spawn(struct_processus *s_et if ((s_copie = copie_objet(s_etat_processus, (*(*s_etat_processus) - .s_liste_variables_partagees).table - [(*(*s_etat_processus).s_liste_variables_partagees) - .position_variable].objet, 'P')) == NULL) + .pointeur_variable_partagee_courante).objet, 'P')) + == NULL) { if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -203,7 +185,7 @@ instruction_spawn(struct_processus *s_et variable_partagee = d_vrai; if (pthread_mutex_unlock(&((*(*s_etat_processus) - .s_liste_variables_partagees).mutex)) != 0) + .pointeur_variable_partagee_courante).mutex)) != 0) { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -353,27 +335,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 @@ -413,8 +397,8 @@ instruction_spawn(struct_processus *s_et (*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; @@ -449,28 +433,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 /* * On copie l'objet plutôt que le pointeur car cet objet peut être @@ -703,10 +689,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) { @@ -1105,7 +1099,11 @@ instruction_smphrdecr(struct_processus * } } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { (*s_etat_processus).erreur_systeme = d_es_processus; return; @@ -1116,7 +1114,12 @@ instruction_smphrdecr(struct_processus * { if (errno != EINTR) { - sem_post(&((*s_etat_processus).semaphore_fork)); +# 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) @@ -1129,15 +1132,22 @@ instruction_smphrdecr(struct_processus * } } - if (sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { - if ((*s_etat_processus).profilage == d_vrai) + if (errno != EINTR) { - profilage(s_etat_processus, NULL); - } + if ((*s_etat_processus).profilage == d_vrai) + { + profilage(s_etat_processus, NULL); + } - (*s_etat_processus).erreur_systeme = d_es_processus; - return; + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } } if ((*s_etat_processus).profilage == d_vrai) @@ -1174,9 +1184,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; @@ -1194,7 +1211,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; } @@ -1206,21 +1224,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; @@ -1229,7 +1296,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; @@ -1245,7 +1312,11 @@ instruction_smphrtrydecr(struct_processu } } - if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) +# else + if (sem_post((*s_etat_processus).semaphore_fork) != 0) +# endif { if ((*s_etat_processus).profilage == d_vrai) { @@ -1256,10 +1327,10 @@ instruction_smphrtrydecr(struct_processu return; } - (*((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) { @@ -1277,32 +1348,40 @@ 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; } } - if (sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# ifndef SEMAPHORES_NOMMES + while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) +# else + while(sem_wait((*s_etat_processus).semaphore_fork) != 0) +# endif { - if ((*s_etat_processus).profilage == d_vrai) + if (errno != EINTR) { - profilage(s_etat_processus, NULL); - } + if ((*s_etat_processus).profilage == d_vrai) + { + profilage(s_etat_processus, NULL); + } - (*s_etat_processus).erreur_systeme = d_es_processus; - return; + (*s_etat_processus).erreur_systeme = d_es_processus; + return; + } } if ((*s_etat_processus).profilage == d_vrai) @@ -1310,13 +1389,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; }