--- rpl/src/instructions_d4.c 2011/06/22 13:26:59 1.26 +++ rpl/src/instructions_d4.c 2019/10/31 15:40:10 1.74 @@ -1,7 +1,7 @@ /* ================================================================================ - RPL/2 (R) version 4.1.0.prerelease.3 - Copyright (C) 1989-2011 Dr. BERTRAND Joël + RPL/2 (R) version 4.1.32 + Copyright (C) 1989-2019 Dr. BERTRAND Joël This file is part of RPL/2. @@ -42,6 +42,8 @@ instruction_delete(struct_processus *s_e file *fichier; + int ios; + integer8 lecture_i64; logical1 erreur; @@ -59,6 +61,8 @@ instruction_delete(struct_processus *s_e struct stat requete; + struct timespec attente; + unsigned char *commande; unsigned char *nom; unsigned char *utf8; @@ -306,9 +310,9 @@ instruction_delete(struct_processus *s_e return; } - if (alsprintf(&commande, "select count(*) from data where " - "id = %lld", (*((integer8 *) (*s_objet_indice).objet))) - < 0) + if (alsprintf(s_etat_processus, &commande, + "select count(*) from data where id = %lld", + (*((integer8 *) (*s_objet_indice).objet))) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -316,18 +320,36 @@ instruction_delete(struct_processus *s_e } if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite, - commande, strlen(commande), &ppStmt, &queue) + commande, (int) strlen(commande), &ppStmt, &queue) != SQLITE_OK) { (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; return; } - if (sqlite3_step(ppStmt) != SQLITE_ROW) + attente.tv_sec = 0; + attente.tv_nsec = GRANULARITE_us * 1000; + + do { - (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; - return; - } + ios = sqlite3_step(ppStmt); + + if (ios == SQLITE_ROW) + { + break; + } + else if ((ios == SQLITE_BUSY) || (ios == SQLITE_LOCKED)) + { + nanosleep(&attente, NULL); + INCR_GRANULARITE(attente.tv_nsec); + } + else + { + (*s_etat_processus).erreur_systeme = + d_es_erreur_fichier; + return; + } + } while(ios != SQLITE_ROW); lecture_i64 = sqlite3_column_int64(ppStmt, 0); @@ -355,7 +377,8 @@ instruction_delete(struct_processus *s_e return; } - if (alsprintf(&commande, "delete from data where id = %lld", + if (alsprintf(s_etat_processus, &commande, + "delete from data where id = %lld", (*((integer8 *) (*s_objet_indice).objet))) < 0) { (*s_etat_processus).erreur_systeme = @@ -364,7 +387,7 @@ instruction_delete(struct_processus *s_e } if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite, - commande, strlen(commande), &ppStmt, &queue) + commande, (int) strlen(commande), &ppStmt, &queue) != SQLITE_OK) { (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; @@ -419,8 +442,9 @@ instruction_delete(struct_processus *s_e return; } - if (alsprintf(&commande, "select id from key where key = " - "'{ \"%s\" }'", utf8) < 0) + if (alsprintf(s_etat_processus, &commande, + "select id from key where key = '{ \"%s\" }'", utf8) + < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -430,48 +454,64 @@ instruction_delete(struct_processus *s_e free(utf8); if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite, - commande, strlen(commande), &ppStmt, &queue) + commande, (int) strlen(commande), &ppStmt, &queue) != SQLITE_OK) { (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; return; } - switch(sqlite3_step(ppStmt)) + attente.tv_sec = 0; + attente.tv_nsec = GRANULARITE_us * 1000; + + do { - case SQLITE_ROW: - { - // Correspondance - break; - } + ios = sqlite3_step(ppStmt); - case SQLITE_DONE: + switch(ios) { - // Aucune correspondance - if (sqlite3_finalize(ppStmt) != SQLITE_OK) + case SQLITE_ROW: { - (*s_etat_processus).erreur_systeme = - d_es_erreur_fichier; - return; + // Correspondance + break; } - free(commande); + case SQLITE_DONE: + { + // Aucune correspondance + if (sqlite3_finalize(ppStmt) != SQLITE_OK) + { + (*s_etat_processus).erreur_systeme = + d_es_erreur_fichier; + return; + } - liberation(s_etat_processus, s_objet_argument); - liberation(s_etat_processus, s_objet_indice); + free(commande); - (*s_etat_processus).erreur_execution = - d_ex_enregistrement_inexistant; - return; - } + liberation(s_etat_processus, s_objet_argument); + liberation(s_etat_processus, s_objet_indice); - default: - { - (*s_etat_processus).erreur_systeme = - d_es_erreur_fichier; - return; + (*s_etat_processus).erreur_execution = + d_ex_enregistrement_inexistant; + return; + } + + case SQLITE_LOCKED: + case SQLITE_BUSY: + { + nanosleep(&attente, NULL); + INCR_GRANULARITE(attente.tv_nsec); + break; + } + + default: + { + (*s_etat_processus).erreur_systeme = + d_es_erreur_fichier; + return; + } } - } + } while(ios != SQLITE_ROW); if (sqlite3_column_type(ppStmt, 0) != SQLITE_INTEGER) { @@ -496,8 +536,9 @@ instruction_delete(struct_processus *s_e free(commande); - if (alsprintf(&commande, "delete from data where key_id = %lld", - lecture_i64) < 0) + if (alsprintf(s_etat_processus, &commande, + "delete from data where key_id = %lld", lecture_i64) + < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -505,7 +546,7 @@ instruction_delete(struct_processus *s_e } if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite, - commande, strlen(commande), &ppStmt, &queue) + commande, (int) strlen(commande), &ppStmt, &queue) != SQLITE_OK) { (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; @@ -527,8 +568,8 @@ instruction_delete(struct_processus *s_e free(commande); - if (alsprintf(&commande, "delete from key where id = %lld", - lecture_i64) < 0) + if (alsprintf(s_etat_processus, &commande, + "delete from key where id = %lld", lecture_i64) < 0) { (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; @@ -536,7 +577,7 @@ instruction_delete(struct_processus *s_e } if (sqlite3_prepare_v2((*descripteur).descripteur_sqlite, - commande, strlen(commande), &ppStmt, &queue) + commande, (int) strlen(commande), &ppStmt, &queue) != SQLITE_OK) { (*s_etat_processus).erreur_systeme = d_es_erreur_fichier; @@ -672,7 +713,7 @@ instruction_drws(struct_processus *s_eta unsigned char *nom_fichier; - unsigned long j; + integer8 j; struct_fichier_graphique *l_fichier_courant; struct_fichier_graphique *l_fichier_precedent; @@ -730,6 +771,9 @@ instruction_drws(struct_processus *s_eta return; } + s_objet_statistique = (*(*s_etat_processus).pointeur_variable_courante) + .objet; + if ((*s_objet_statistique).type == MIN) { matrice_entiere = d_vrai; @@ -812,10 +856,10 @@ instruction_drws(struct_processus *s_eta if (((*s_etat_processus).colonne_statistique_1 < 1) || ((*s_etat_processus).colonne_statistique_2 < 1) || - ((*s_etat_processus).colonne_statistique_1 > (signed long) + ((*s_etat_processus).colonne_statistique_1 > (*((struct_matrice *) (*s_objet_statistique).objet)) .nombre_colonnes) || - ((*s_etat_processus).colonne_statistique_2 > (signed long) + ((*s_etat_processus).colonne_statistique_2 > (*((struct_matrice *) (*s_objet_statistique).objet)) .nombre_colonnes)) { @@ -1066,18 +1110,11 @@ instruction_decr(struct_processus *s_eta 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) { (*s_etat_processus).erreur_systeme = d_es; (*s_etat_processus).erreur_execution = @@ -1087,9 +1124,7 @@ instruction_decr(struct_processus *s_eta } s_objet_argument = (*(*s_etat_processus) - .s_liste_variables_partagees).table - [(*(*s_etat_processus).s_liste_variables_partagees) - .position_variable].objet; + .pointeur_variable_partagee_courante).objet; variable_partagee = d_vrai; } else @@ -1105,7 +1140,7 @@ instruction_decr(struct_processus *s_eta if (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; @@ -1121,10 +1156,8 @@ instruction_decr(struct_processus *s_eta if (variable_partagee == d_vrai) { (*(*s_etat_processus).pointeur_variable_courante).objet = NULL; - (*(*s_etat_processus) - .s_liste_variables_partagees).table - [(*(*s_etat_processus).s_liste_variables_partagees) - .position_variable].objet = s_copie_argument; + (*(*s_etat_processus).pointeur_variable_partagee_courante).objet = + s_copie_argument; } else { @@ -1139,7 +1172,7 @@ instruction_decr(struct_processus *s_eta if (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; @@ -1151,7 +1184,7 @@ instruction_decr(struct_processus *s_eta if (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;