--- rpl/src/rpl.c 2010/04/07 13:45:10 1.16 +++ rpl/src/rpl.c 2010/04/17 18:57:36 1.17 @@ -102,26 +102,75 @@ rplinit(int argc, char *argv[], unsigned setvbuf(stdout, NULL, _IOLBF, 0); setvbuf(stderr, NULL, _IOLBF, 0); +# ifndef SEMAPHORES_NOMMES sem_init(&semaphore_liste_threads, 0, 1); sem_init(&semaphore_gestionnaires_signaux, 0, 0); sem_init(&semaphore_gestionnaires_signaux_atomique, 0, 1); +# else + semaphore_liste_threads = sem_init2(1, sem_liste_threads); + semaphore_gestionnaires_signaux = sem_init2(0, sem_gestionnaires_signaux); + semaphore_gestionnaires_signaux_atomique = sem_init2(1, + sem_gestionnaires_signaux_atomique); + + if ((semaphore_liste_threads == SEM_FAILED) || + (semaphore_gestionnaires_signaux == SEM_FAILED) || + (semaphore_gestionnaires_signaux_atomique == SEM_FAILED)) + { + erreur = d_es_allocation_memoire; + + if ((langue = getenv("LANG")) != NULL) + { + if (strncmp(langue, "fr", 2) == 0) + { + uprintf("+++Système : Mémoire insuffisante\n"); + } + else + { + uprintf("+++System : Not enough memory\n"); + } + } + else + { + uprintf("+++System : Not enough memory\n"); + } + + return(EXIT_FAILURE); + } +# endif if ((s_etat_processus = malloc(sizeof(struct_processus))) == NULL) { erreur = d_es_allocation_memoire; - if ((*s_etat_processus).langue == 'F') + if ((langue = getenv("LANG")) != NULL) { - printf("+++Système : Mémoire insuffisante\n"); + if (strncmp(langue, "fr", 2) == 0) + { + uprintf("+++Système : Mémoire insuffisante\n"); + } + else + { + uprintf("+++System : Not enough memory\n"); + } } else { - printf("+++System : Not enough memory\n"); + uprintf("+++System : Not enough memory\n"); } return(EXIT_FAILURE); } + if ((langue = getenv("LANG")) != NULL) + { + (*s_etat_processus).langue = (strncmp(langue, "fr", 2) == 0) + ? 'F' : 'E'; + } + else + { + (*s_etat_processus).langue = 'E'; + } + (*s_etat_processus).exception = d_ep; (*s_etat_processus).erreur_systeme = d_es; (*s_etat_processus).erreur_execution = d_ex; @@ -135,7 +184,24 @@ rplinit(int argc, char *argv[], unsigned pthread_mutex_init(&((*s_etat_processus).mutex), &attributs_mutex); pthread_mutexattr_destroy(&attributs_mutex); +# ifndef SEMAPHORES_NOMMES sem_init(&((*s_etat_processus).semaphore_fork), 0, 0); +# else + if (((*s_etat_processus).semaphore_fork = sem_init2(0, sem_fork)) == + SEM_FAILED) + { + if ((*s_etat_processus).langue == 'F') + { + uprintf("+++Système : Mémoire insuffisante\n"); + } + else + { + uprintf("+++System : Not enough memory\n"); + } + + return(EXIT_FAILURE); + } +# endif pthread_mutexattr_init(&attributs_mutex); pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_NORMAL); @@ -155,30 +221,27 @@ rplinit(int argc, char *argv[], unsigned .mutex), &attributs_mutex); pthread_mutexattr_destroy(&attributs_mutex); - if ((langue = getenv("LANG")) != NULL) - { - (*s_etat_processus).langue = (strncmp(langue, "fr", 2) == 0) - ? 'F' : 'E'; - } - else - { - (*s_etat_processus).langue = 'E'; - } - localisation_courante(s_etat_processus); + (*s_etat_processus).erreur_systeme = d_es; - if ((*s_etat_processus).erreur_systeme != d_es) + if ((*s_etat_processus).localisation == NULL) { - if ((*s_etat_processus).langue == 'F') + if (((*s_etat_processus).localisation = malloc((strlen(d_locale) + 1) * + sizeof(unsigned char))) == NULL) { - printf("+++Système : Mémoire insuffisante\n"); - } - else - { - printf("+++System : Not enough memory\n"); + if ((*s_etat_processus).langue == 'F') + { + uprintf("+++Système : Mémoire insuffisante\n"); + } + else + { + uprintf("+++System : Not enough memory\n"); + } + + return(EXIT_FAILURE); } - return(EXIT_FAILURE); + strcpy((*s_etat_processus).localisation, d_locale); } printf("+++RPL/2 (R) version %s (%s)\n", d_version_rpl, @@ -231,8 +294,13 @@ rplinit(int argc, char *argv[], unsigned return(EXIT_FAILURE); } +# ifndef SEMAPHORES_NOMMES if (pthread_setspecific(semaphore_fork_processus_courant, &((*s_etat_processus).semaphore_fork)) != 0) +# else + if (pthread_setspecific(semaphore_fork_processus_courant, + (*s_etat_processus).semaphore_fork) != 0) +# endif { if ((*s_etat_processus).langue == 'F') { @@ -1272,6 +1340,7 @@ rplinit(int argc, char *argv[], unsigned return(EXIT_FAILURE); } + free(type_debug); break; } @@ -3331,16 +3400,32 @@ rplinit(int argc, char *argv[], unsigned retrait_thread(s_etat_processus); pthread_mutex_destroy(&((*s_etat_processus).mutex)); +# 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_destroy2((*s_etat_processus).semaphore_fork, sem_fork); +# endif free((*s_etat_processus).localisation); free(s_etat_processus); +# ifndef SEMAPHORES_NOMMES sem_destroy(&semaphore_liste_threads); +# else + sem_destroy2(semaphore_liste_threads, sem_liste_threads); +# endif +# ifndef SEMAPHORES_NOMMES sem_post(&semaphore_gestionnaires_signaux); sem_destroy(&semaphore_gestionnaires_signaux); sem_destroy(&semaphore_gestionnaires_signaux_atomique); +# else + sem_post(semaphore_gestionnaires_signaux); + sem_destroy2(semaphore_gestionnaires_signaux, sem_gestionnaires_signaux); + sem_destroy2(semaphore_gestionnaires_signaux_atomique, + sem_gestionnaires_signaux_atomique); +# endif # ifdef DEBUG_MEMOIRE debug_memoire_verification(s_etat_processus);