--- rpl/src/instructions_s10.c 2011/10/04 19:32:35 1.50 +++ rpl/src/instructions_s10.c 2012/10/01 11:05:06 1.62 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.4 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.11 + 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; @@ -415,8 +414,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; @@ -707,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) { @@ -1194,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; @@ -1214,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; } @@ -1226,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; @@ -1249,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; @@ -1280,10 +1344,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) { @@ -1301,18 +1365,19 @@ 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; } @@ -1341,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; }