Annotation of rpl/src/instructions_s10.c, revision 1.1
1.1 ! bertrand 1: /*
! 2: ================================================================================
! 3: RPL/2 (R) version 4.0.9
! 4: Copyright (C) 1989-2010 Dr. BERTRAND Joël
! 5:
! 6: This file is part of RPL/2.
! 7:
! 8: RPL/2 is free software; you can redistribute it and/or modify it
! 9: under the terms of the CeCILL V2 License as published by the french
! 10: CEA, CNRS and INRIA.
! 11:
! 12: RPL/2 is distributed in the hope that it will be useful, but WITHOUT
! 13: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
! 14: FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL V2 License
! 15: for more details.
! 16:
! 17: You should have received a copy of the CeCILL License
! 18: along with RPL/2. If not, write to info@cecill.info.
! 19: ================================================================================
! 20: */
! 21:
! 22:
! 23: #include "rpl.conv.h"
! 24:
! 25:
! 26: /*
! 27: ================================================================================
! 28: Fonction 'spawn'
! 29: ================================================================================
! 30: Entrées :
! 31: --------------------------------------------------------------------------------
! 32: Sorties :
! 33: --------------------------------------------------------------------------------
! 34: Effets de bord : néant
! 35: ================================================================================
! 36: */
! 37:
! 38: void
! 39: instruction_spawn(struct_processus *s_etat_processus)
! 40: {
! 41: logical1 drapeau;
! 42: logical1 variable_partagee;
! 43:
! 44: pthread_attr_t attributs;
! 45:
! 46: pthread_mutexattr_t attributs_mutex;
! 47:
! 48: pthread_t thread_id;
! 49: pthread_t thread_surveillance;
! 50:
! 51: sigset_t oldset;
! 52: sigset_t set;
! 53:
! 54: struct_descripteur_thread *s_argument_thread;
! 55:
! 56: struct_liste_chainee *l_element_courant;
! 57:
! 58: struct_objet *s_copie;
! 59: struct_objet *s_objet;
! 60: struct_objet *s_objet_resultat;
! 61: struct_objet *s_objet_systeme;
! 62:
! 63: struct_processus *s_nouvel_etat_processus;
! 64:
! 65: struct timespec attente;
! 66:
! 67: (*s_etat_processus).erreur_execution = d_ex;
! 68:
! 69: if ((*s_etat_processus).affichage_arguments == 'Y')
! 70: {
! 71: printf("\n SPAWN ");
! 72:
! 73: if ((*s_etat_processus).langue == 'F')
! 74: {
! 75: printf("(lancement d'un thread)\n\n");
! 76: }
! 77: else
! 78: {
! 79: printf("(create thread)\n\n");
! 80: }
! 81:
! 82: printf(" 1: %s, %s\n", d_NOM, d_RPN);
! 83: printf("-> 1: %s\n", d_PRC);
! 84:
! 85: return;
! 86: }
! 87: else if ((*s_etat_processus).test_instruction == 'Y')
! 88: {
! 89: (*s_etat_processus).nombre_arguments = -1;
! 90: return;
! 91: }
! 92:
! 93: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 94: {
! 95: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 96: {
! 97: return;
! 98: }
! 99: }
! 100:
! 101: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 102: &s_objet) == d_erreur)
! 103: {
! 104: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 105: return;
! 106: }
! 107:
! 108: /*
! 109: * Une routine fille doit pouvoir renvoyer des objets au processus
! 110: * père au travers de la fonction SEND. Il ne peut donc s'agir que
! 111: * d'une fonction ou d'une expression RPN.
! 112: */
! 113:
! 114: if (((*s_objet).type != NOM) &&
! 115: ((*s_objet).type != RPN))
! 116: {
! 117: liberation(s_etat_processus, s_objet);
! 118:
! 119: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 120: return;
! 121: }
! 122:
! 123: /*
! 124: * Si l'argument est de type NOM, il faut que la variable correspondante
! 125: * soit une variable de type RPN.
! 126: */
! 127:
! 128: variable_partagee = d_faux;
! 129: s_copie = NULL;
! 130:
! 131: if ((*s_objet).type == NOM)
! 132: {
! 133: if (recherche_variable(s_etat_processus, (*((struct_nom *)
! 134: (*s_objet).objet)).nom) == d_vrai)
! 135: {
! 136: if ((*s_etat_processus).s_liste_variables
! 137: [(*s_etat_processus).position_variable_courante].objet
! 138: == NULL)
! 139: {
! 140: if (pthread_mutex_lock(&((*(*s_etat_processus)
! 141: .s_liste_variables_partagees).mutex)) != 0)
! 142: {
! 143: (*s_etat_processus).erreur_systeme = d_es_processus;
! 144: return;
! 145: }
! 146:
! 147: if (recherche_variable_partagee(s_etat_processus,
! 148: (*s_etat_processus).s_liste_variables
! 149: [(*s_etat_processus).position_variable_courante].nom,
! 150: (*s_etat_processus).s_liste_variables
! 151: [(*s_etat_processus).position_variable_courante]
! 152: .variable_partagee, (*s_etat_processus)
! 153: .s_liste_variables[(*s_etat_processus)
! 154: .position_variable_courante].origine) == d_faux)
! 155: {
! 156: if (pthread_mutex_unlock(&((*(*s_etat_processus)
! 157: .s_liste_variables_partagees).mutex)) != 0)
! 158: {
! 159: (*s_etat_processus).erreur_systeme = d_es_processus;
! 160: return;
! 161: }
! 162:
! 163: liberation(s_etat_processus, s_objet);
! 164:
! 165: (*s_etat_processus).erreur_systeme = d_es;
! 166: (*s_etat_processus).erreur_execution =
! 167: d_ex_argument_invalide;
! 168: return;
! 169: }
! 170:
! 171: if (((*(*(*s_etat_processus).s_liste_variables_partagees)
! 172: .table[(*(*s_etat_processus)
! 173: .s_liste_variables_partagees).position_variable].objet)
! 174: .type != RPN) && ((*(*(*s_etat_processus)
! 175: .s_liste_variables_partagees).table
! 176: [(*(*s_etat_processus).s_liste_variables_partagees)
! 177: .position_variable].objet).type != ADR))
! 178: {
! 179: if (pthread_mutex_unlock(&((*(*s_etat_processus)
! 180: .s_liste_variables_partagees).mutex)) != 0)
! 181: {
! 182: (*s_etat_processus).erreur_systeme = d_es_processus;
! 183: return;
! 184: }
! 185:
! 186: liberation(s_etat_processus, s_objet);
! 187:
! 188: (*s_etat_processus).erreur_execution =
! 189: d_ex_argument_invalide;
! 190: return;
! 191: }
! 192:
! 193: if ((s_copie = copie_objet(s_etat_processus,
! 194: (*(*s_etat_processus)
! 195: .s_liste_variables_partagees).table
! 196: [(*(*s_etat_processus).s_liste_variables_partagees)
! 197: .position_variable].objet, 'P')) == NULL)
! 198: {
! 199: if (pthread_mutex_unlock(&((*(*s_etat_processus)
! 200: .s_liste_variables_partagees).mutex)) != 0)
! 201: {
! 202: (*s_etat_processus).erreur_systeme = d_es_processus;
! 203: return;
! 204: }
! 205:
! 206: (*s_etat_processus).erreur_systeme =
! 207: d_es_allocation_memoire;
! 208:
! 209: return;
! 210: }
! 211:
! 212: variable_partagee = d_vrai;
! 213:
! 214: if (pthread_mutex_unlock(&((*(*s_etat_processus)
! 215: .s_liste_variables_partagees).mutex)) != 0)
! 216: {
! 217: (*s_etat_processus).erreur_systeme = d_es_processus;
! 218: return;
! 219: }
! 220: }
! 221: else
! 222: {
! 223: if (((*(*s_etat_processus).s_liste_variables
! 224: [(*s_etat_processus).position_variable_courante].objet)
! 225: .type != RPN) && ((*(*s_etat_processus)
! 226: .s_liste_variables[(*s_etat_processus)
! 227: .position_variable_courante].objet).type != ADR))
! 228: {
! 229: liberation(s_etat_processus, s_objet);
! 230:
! 231: (*s_etat_processus).erreur_execution =
! 232: d_ex_argument_invalide;
! 233: return;
! 234: }
! 235: }
! 236: }
! 237: else // Variable inexistante
! 238: {
! 239: liberation(s_etat_processus, s_objet);
! 240:
! 241: (*s_etat_processus).erreur_systeme = d_es;
! 242: (*s_etat_processus).erreur_execution = d_ex_argument_invalide;
! 243: return;
! 244: }
! 245: }
! 246:
! 247: if (sigemptyset(&set) != 0)
! 248: {
! 249: (*s_etat_processus).erreur_systeme = d_es_processus;
! 250: return;
! 251: }
! 252:
! 253: if (sigaddset(&set, SIGSTART) != 0)
! 254: {
! 255: (*s_etat_processus).erreur_systeme = d_es_processus;
! 256: return;
! 257: }
! 258:
! 259: /*
! 260: * Le signal SIGFSTOP doit être traité !
! 261: */
! 262:
! 263: if (sigaddset(&set, SIGFSTOP) != 0)
! 264: {
! 265: (*s_etat_processus).erreur_systeme = d_es_processus;
! 266: return;
! 267: }
! 268:
! 269: if (sigaddset(&set, SIGURG) != 0)
! 270: {
! 271: (*s_etat_processus).erreur_systeme = d_es_processus;
! 272: return;
! 273: }
! 274:
! 275: if (pthread_sigmask(SIG_BLOCK, &set, &oldset) != 0)
! 276: {
! 277: (*s_etat_processus).erreur_systeme = d_es_processus;
! 278: return;
! 279: }
! 280:
! 281: if ((s_argument_thread = malloc(sizeof(struct_descripteur_thread))) == NULL)
! 282: {
! 283: (*s_etat_processus).erreur_systeme = d_es_processus;
! 284: return;
! 285: }
! 286:
! 287: if (pipe((*s_argument_thread).pipe_erreurs) != 0)
! 288: {
! 289: (*s_etat_processus).erreur_systeme = d_es_processus;
! 290: return;
! 291: }
! 292:
! 293: if (pipe((*s_argument_thread).pipe_interruptions) != 0)
! 294: {
! 295: (*s_etat_processus).erreur_systeme = d_es_processus;
! 296: return;
! 297: }
! 298:
! 299: if (pipe((*s_argument_thread).pipe_nombre_interruptions_attente) != 0)
! 300: {
! 301: (*s_etat_processus).erreur_systeme = d_es_processus;
! 302: return;
! 303: }
! 304:
! 305: if (pipe((*s_argument_thread).pipe_objets) != 0)
! 306: {
! 307: (*s_etat_processus).erreur_systeme = d_es_processus;
! 308: return;
! 309: }
! 310:
! 311: if (pipe((*s_argument_thread).pipe_acquittement) != 0)
! 312: {
! 313: (*s_etat_processus).erreur_systeme = d_es_processus;
! 314: return;
! 315: }
! 316:
! 317: if (pipe((*s_argument_thread).pipe_nombre_objets_attente) != 0)
! 318: {
! 319: (*s_etat_processus).erreur_systeme = d_es_processus;
! 320: return;
! 321: }
! 322:
! 323: if (pipe((*s_argument_thread).pipe_injections) != 0)
! 324: {
! 325: (*s_etat_processus).erreur_systeme = d_es_processus;
! 326: return;
! 327: }
! 328:
! 329: if (pipe((*s_argument_thread).pipe_nombre_injections) != 0)
! 330: {
! 331: (*s_etat_processus).erreur_systeme = d_es_processus;
! 332: return;
! 333: }
! 334:
! 335: if ((s_nouvel_etat_processus = copie_etat_processus(s_etat_processus))
! 336: == NULL)
! 337: {
! 338: return;
! 339: }
! 340:
! 341: pthread_mutexattr_init(&attributs_mutex);
! 342: pthread_mutexattr_settype(&attributs_mutex, PTHREAD_MUTEX_RECURSIVE);
! 343: pthread_mutex_init(&((*s_argument_thread).mutex), &attributs_mutex);
! 344: pthread_mutexattr_destroy(&attributs_mutex);
! 345:
! 346: (*s_argument_thread).processus_detache = d_faux;
! 347: (*s_argument_thread).thread_actif = d_faux;
! 348: (*s_argument_thread).thread_pere = pthread_self();
! 349: (*s_argument_thread).pid = getpid();
! 350:
! 351: (*s_nouvel_etat_processus).pipe_donnees =
! 352: (*s_argument_thread).pipe_objets[1];
! 353: (*s_nouvel_etat_processus).pipe_nombre_objets_attente =
! 354: (*s_argument_thread).pipe_nombre_objets_attente[1];
! 355: (*s_nouvel_etat_processus).pipe_interruptions =
! 356: (*s_argument_thread).pipe_interruptions[1];
! 357: (*s_nouvel_etat_processus).pipe_nombre_interruptions_attente =
! 358: (*s_argument_thread).pipe_nombre_interruptions_attente[1];
! 359: (*s_nouvel_etat_processus).pipe_injections =
! 360: (*s_argument_thread).pipe_injections[0];
! 361: (*s_nouvel_etat_processus).pipe_nombre_injections =
! 362: (*s_argument_thread).pipe_nombre_injections[0];
! 363: (*s_nouvel_etat_processus).pipe_acquittement =
! 364: (*s_argument_thread).pipe_acquittement[0];
! 365: (*s_nouvel_etat_processus).presence_pipes = d_vrai;
! 366:
! 367: (*s_nouvel_etat_processus).niveau_initial =
! 368: (*s_etat_processus).niveau_courant;
! 369: (*s_nouvel_etat_processus).debug_programme = d_faux;
! 370: (*s_nouvel_etat_processus).nombre_objets_injectes = 0;
! 371: (*s_nouvel_etat_processus).nombre_objets_envoyes_non_lus = 0;
! 372: (*s_nouvel_etat_processus).temps_maximal_cpu = 0;
! 373: (*s_nouvel_etat_processus).presence_fusible = d_faux;
! 374: (*s_nouvel_etat_processus).thread_fusible = 0;
! 375:
! 376: (*s_nouvel_etat_processus).pile_profilage = NULL;
! 377: (*s_nouvel_etat_processus).pile_profilage_fonctions = NULL;
! 378:
! 379: /*
! 380: * Lancement du thread fils et du thread de surveillance
! 381: */
! 382:
! 383: if (pthread_attr_init(&attributs) != 0)
! 384: {
! 385: (*s_etat_processus).erreur_systeme = d_es_processus;
! 386: return;
! 387: }
! 388:
! 389: if (pthread_attr_setdetachstate(&attributs, PTHREAD_CREATE_JOINABLE) != 0)
! 390: {
! 391: (*s_etat_processus).erreur_systeme = d_es_processus;
! 392: return;
! 393: }
! 394:
! 395: if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0)
! 396: {
! 397: (*s_etat_processus).erreur_systeme = d_es_processus;
! 398: return;
! 399: }
! 400:
! 401: if (pthread_attr_setinheritsched(&attributs, PTHREAD_EXPLICIT_SCHED) != 0)
! 402: {
! 403: (*s_etat_processus).erreur_systeme = d_es_processus;
! 404: return;
! 405: }
! 406:
! 407: if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0)
! 408: {
! 409: (*s_etat_processus).erreur_systeme = d_es_processus;
! 410: return;
! 411: }
! 412:
! 413: /*
! 414: * Création de l'objet à retourner
! 415: */
! 416:
! 417: if ((s_objet_resultat = allocation(s_etat_processus, PRC)) == NULL)
! 418: {
! 419: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 420: return;
! 421: }
! 422:
! 423: (*((struct_processus_fils *) (*s_objet_resultat).objet)).thread
! 424: = s_argument_thread;
! 425:
! 426: (*(*((struct_processus_fils *) (*s_objet_resultat).objet)).thread)
! 427: .nombre_objets_dans_pipe = 0;
! 428: (*(*((struct_processus_fils *) (*s_objet_resultat).objet)).thread)
! 429: .nombre_interruptions_dans_pipe = 0;
! 430: (*(*((struct_processus_fils *) (*s_objet_resultat).objet)).thread)
! 431: .nombre_references = 1;
! 432:
! 433: // Lancement du thread fils
! 434:
! 435: if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0)
! 436: {
! 437: (*s_etat_processus).erreur_systeme = d_es_processus;
! 438: return;
! 439: }
! 440:
! 441: (*s_argument_thread).s_nouvel_etat_processus = s_nouvel_etat_processus;
! 442: (*s_argument_thread).s_etat_processus = s_etat_processus;
! 443:
! 444: if (variable_partagee == d_vrai)
! 445: {
! 446: (*s_argument_thread).argument = s_copie;
! 447: (*s_argument_thread).destruction_objet = d_vrai;
! 448: }
! 449: else
! 450: {
! 451: (*s_argument_thread).argument = s_objet;
! 452: (*s_argument_thread).destruction_objet = d_faux;
! 453: }
! 454:
! 455: (*s_argument_thread).set = set;
! 456: (*s_argument_thread).oldset = oldset;
! 457:
! 458: if (pthread_create(&thread_id, &attributs, lancement_thread,
! 459: s_argument_thread) != 0)
! 460: {
! 461: (*s_etat_processus).erreur_systeme = d_es_processus;
! 462: return;
! 463: }
! 464:
! 465: if (pthread_attr_destroy(&attributs) != 0)
! 466: {
! 467: (*s_etat_processus).erreur_systeme = d_es_processus;
! 468: return;
! 469: }
! 470:
! 471: if (pthread_attr_init(&attributs) != 0)
! 472: {
! 473: (*s_etat_processus).erreur_systeme = d_es_processus;
! 474: return;
! 475: }
! 476:
! 477: if (pthread_attr_setdetachstate(&attributs,
! 478: PTHREAD_CREATE_DETACHED) != 0)
! 479: {
! 480: (*s_etat_processus).erreur_systeme = d_es_processus;
! 481: return;
! 482: }
! 483:
! 484: if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0)
! 485: {
! 486: (*s_etat_processus).erreur_systeme = d_es_processus;
! 487: return;
! 488: }
! 489:
! 490: if (pthread_attr_setinheritsched(&attributs,
! 491: PTHREAD_EXPLICIT_SCHED) != 0)
! 492: {
! 493: (*s_etat_processus).erreur_systeme = d_es_processus;
! 494: return;
! 495: }
! 496:
! 497: if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0)
! 498: {
! 499: (*s_etat_processus).erreur_systeme = d_es_processus;
! 500: return;
! 501: }
! 502:
! 503: // Attente de l'affectation de la grandeur processus.tid par le thread fils.
! 504:
! 505: if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0)
! 506: {
! 507: (*s_etat_processus).erreur_systeme = d_es_processus;
! 508: return;
! 509: }
! 510:
! 511: /*
! 512: * On copie l'objet plutôt que le pointeur car cet objet peut être
! 513: * accédé depuis deux threads distincts et aboutir à un blocage lors d'une
! 514: * copie.
! 515: */
! 516:
! 517: if ((s_objet_systeme = copie_objet(s_etat_processus, s_objet_resultat, 'O'))
! 518: == NULL)
! 519: {
! 520: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 521: return;
! 522: }
! 523:
! 524: if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
! 525: {
! 526: (*s_etat_processus).erreur_systeme = d_es_processus;
! 527: return;
! 528: }
! 529:
! 530: // Si le tid existe déjà dans la pile des processus, il s'agit forcement
! 531: // d'un processus moribond. On attend donc qu'il soit effectivement
! 532: // libéré.
! 533:
! 534: do
! 535: {
! 536: l_element_courant = (struct_liste_chainee *)
! 537: (*s_etat_processus).l_base_pile_processus;
! 538: drapeau = d_faux;
! 539:
! 540: attente.tv_sec = 0;
! 541: attente.tv_nsec = GRANULARITE_us * 1000;
! 542:
! 543: while(l_element_courant != NULL)
! 544: {
! 545: if (((*(*((struct_processus_fils *)
! 546: (*(*l_element_courant).donnee).objet)).thread)
! 547: .processus_detache == d_faux) &&
! 548: ((*s_argument_thread).processus_detache == d_faux))
! 549: {
! 550: if (pthread_equal((*(*((struct_processus_fils *)
! 551: (*(*l_element_courant).donnee).objet)).thread)
! 552: .tid, (*s_argument_thread).tid) != 0)
! 553: {
! 554: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
! 555: {
! 556: (*s_etat_processus).erreur_systeme = d_es_processus;
! 557: return;
! 558: }
! 559:
! 560: scrutation_injection(s_etat_processus);
! 561:
! 562: if ((*s_etat_processus).nombre_interruptions_non_affectees
! 563: != 0)
! 564: {
! 565: affectation_interruptions_logicielles(s_etat_processus);
! 566: }
! 567:
! 568: if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
! 569: {
! 570: traitement_interruptions_logicielles(s_etat_processus);
! 571: }
! 572:
! 573: nanosleep(&attente, NULL);
! 574: INCR_GRANULARITE(attente.tv_nsec);
! 575:
! 576: if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0)
! 577: {
! 578: (*s_etat_processus).erreur_systeme = d_es_processus;
! 579: return;
! 580: }
! 581:
! 582: drapeau = d_vrai;
! 583: break;
! 584: }
! 585: }
! 586:
! 587: l_element_courant = (*l_element_courant).suivant;
! 588: }
! 589: } while(drapeau == d_vrai);
! 590:
! 591: if (empilement(s_etat_processus,
! 592: (struct_liste_chainee **) &((*s_etat_processus)
! 593: .l_base_pile_processus), s_objet_systeme) == d_erreur)
! 594: {
! 595: pthread_mutex_unlock(&((*s_etat_processus).mutex));
! 596: pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex));
! 597: return;
! 598: }
! 599:
! 600: if (pthread_mutex_unlock(&((*s_etat_processus).mutex)) != 0)
! 601: {
! 602: (*s_etat_processus).erreur_systeme = d_es_processus;
! 603: return;
! 604: }
! 605:
! 606: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 607: s_objet_resultat) == d_erreur)
! 608: {
! 609: pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex));
! 610: return;
! 611: }
! 612:
! 613: if (pthread_mutex_lock(&(*s_argument_thread).mutex) != 0)
! 614: {
! 615: pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex));
! 616: (*s_etat_processus).erreur_systeme = d_es_processus;
! 617: return;
! 618: }
! 619:
! 620: if ((*s_argument_thread).thread_actif == d_faux)
! 621: {
! 622: // Le thread n'existe plus.
! 623:
! 624: pthread_join((*s_argument_thread).tid, NULL);
! 625: pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex));
! 626: pthread_mutex_unlock(&(*s_argument_thread).mutex);
! 627: (*s_etat_processus).erreur_systeme = d_es_processus;
! 628: return;
! 629: }
! 630:
! 631: if (pthread_mutex_unlock(&(*s_argument_thread).mutex) != 0)
! 632: {
! 633: pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex));
! 634: (*s_etat_processus).erreur_systeme = d_es_processus;
! 635: return;
! 636: }
! 637:
! 638: if (pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)) != 0)
! 639: {
! 640: (*s_etat_processus).erreur_systeme = d_es_processus;
! 641: return;
! 642: }
! 643:
! 644: // Lancement du thread de surveillance
! 645:
! 646: if (pthread_create(&thread_surveillance, &attributs,
! 647: surveillance_processus, s_argument_thread) != 0)
! 648: {
! 649: (*s_etat_processus).erreur_systeme = d_es_processus;
! 650: return;
! 651: }
! 652:
! 653: if (pthread_attr_destroy(&attributs) != 0)
! 654: {
! 655: (*s_etat_processus).erreur_systeme = d_es_processus;
! 656: return;
! 657: }
! 658:
! 659: // Le fils peut être présent sans être en attente du signal de départ.
! 660:
! 661: if (pthread_kill((*s_argument_thread).tid, SIGSTART) != 0)
! 662: {
! 663: (*s_etat_processus).erreur_systeme = d_es_processus;
! 664: return;
! 665: }
! 666:
! 667: if (pthread_sigmask(SIG_SETMASK, &oldset, NULL) != 0)
! 668: {
! 669: (*s_etat_processus).erreur_systeme = d_es_processus;
! 670: return;
! 671: }
! 672:
! 673: sigpending(&set);
! 674:
! 675: return;
! 676: }
! 677:
! 678:
! 679: /*
! 680: ================================================================================
! 681: Fonction 'sqlconnect'
! 682: ================================================================================
! 683: Entrées :
! 684: --------------------------------------------------------------------------------
! 685: Sorties :
! 686: --------------------------------------------------------------------------------
! 687: Effets de bord : néant
! 688: ================================================================================
! 689: */
! 690:
! 691: void
! 692: instruction_sqlconnect(struct_processus *s_etat_processus)
! 693: {
! 694: struct_objet *s_objet_argument;
! 695: struct_objet *s_objet_resultat;
! 696: struct_objet *s_objet_systeme;
! 697:
! 698: (*s_etat_processus).erreur_execution = d_ex;
! 699:
! 700: if ((*s_etat_processus).affichage_arguments == 'Y')
! 701: {
! 702: printf("\n SQLCONNECT ");
! 703:
! 704: if ((*s_etat_processus).langue == 'F')
! 705: {
! 706: printf("(connexion à une base de données SQL)\n\n");
! 707: }
! 708: else
! 709: {
! 710: printf("(connect to SQL database)\n\n");
! 711: }
! 712:
! 713: printf(" 1: %s\n", d_LST);
! 714: printf("-> 1: %s\n\n", d_SQL);
! 715:
! 716: if ((*s_etat_processus).langue == 'F')
! 717: {
! 718: printf(" Utilisation :\n\n");
! 719: }
! 720: else
! 721: {
! 722: printf(" Usage:\n\n");
! 723: }
! 724:
! 725: printf(" { \"mysql\" \"server\" \"database\" "
! 726: "\"user\" \"password\" } SQLCONNECT\n");
! 727: printf(" { \"postgresql:iso-8859-1\" \"server\" "
! 728: "\"database\" \"user\" \"password\" port }\n");
! 729: printf(" SQLCONNECT\n");
! 730:
! 731: return;
! 732: }
! 733: else if ((*s_etat_processus).test_instruction == 'Y')
! 734: {
! 735: (*s_etat_processus).nombre_arguments = -1;
! 736: return;
! 737: }
! 738:
! 739: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 740: {
! 741: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 742: {
! 743: return;
! 744: }
! 745: }
! 746:
! 747: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 748: &s_objet_argument) == d_erreur)
! 749: {
! 750: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 751: return;
! 752: }
! 753:
! 754: if ((*s_objet_argument).type == LST)
! 755: {
! 756: if ((s_objet_resultat = parametres_sql(s_etat_processus,
! 757: s_objet_argument)) == NULL)
! 758: {
! 759: liberation(s_etat_processus, s_objet_argument);
! 760: return;
! 761: }
! 762:
! 763: if ((s_objet_systeme = copie_objet(s_etat_processus, s_objet_resultat,
! 764: 'O')) == NULL)
! 765: {
! 766: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 767: return;
! 768: }
! 769:
! 770: if (empilement(s_etat_processus,
! 771: (struct_liste_chainee **) &((*s_etat_processus)
! 772: .s_connecteurs_sql), s_objet_systeme) == d_erreur)
! 773: {
! 774: return;
! 775: }
! 776:
! 777: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 778: s_objet_resultat) == d_erreur)
! 779: {
! 780: return;
! 781: }
! 782: }
! 783: else
! 784: {
! 785: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 786:
! 787: liberation(s_etat_processus, s_objet_argument);
! 788: return;
! 789: }
! 790:
! 791: liberation(s_etat_processus, s_objet_argument);
! 792: return;
! 793: }
! 794:
! 795:
! 796: /*
! 797: ================================================================================
! 798: Fonction 'sqlconnect'
! 799: ================================================================================
! 800: Entrées :
! 801: --------------------------------------------------------------------------------
! 802: Sorties :
! 803: --------------------------------------------------------------------------------
! 804: Effets de bord : néant
! 805: ================================================================================
! 806: */
! 807:
! 808: void
! 809: instruction_sqldisconnect(struct_processus *s_etat_processus)
! 810: {
! 811: logical1 drapeau;
! 812:
! 813: struct_liste_chainee *l_element_courant;
! 814: struct_liste_chainee *l_element_precedent;
! 815:
! 816: struct_objet *s_objet;
! 817:
! 818: (*s_etat_processus).erreur_execution = d_ex;
! 819:
! 820: if ((*s_etat_processus).affichage_arguments == 'Y')
! 821: {
! 822: printf("\n SQLDISCONNECT ");
! 823:
! 824: if ((*s_etat_processus).langue == 'F')
! 825: {
! 826: printf("(déconnexion d'une base de donnée SQL)\n\n");
! 827: }
! 828: else
! 829: {
! 830: printf("(disconnection from SQL database)\n\n");
! 831: }
! 832:
! 833: printf(" 1: %s\n", d_SQL);
! 834: return;
! 835: }
! 836: else if ((*s_etat_processus).test_instruction == 'Y')
! 837: {
! 838: (*s_etat_processus).nombre_arguments = -1;
! 839: return;
! 840: }
! 841:
! 842: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 843: {
! 844: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 845: {
! 846: return;
! 847: }
! 848: }
! 849:
! 850: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 851: &s_objet) == d_erreur)
! 852: {
! 853: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 854: return;
! 855: }
! 856:
! 857: if ((*s_objet).type == SQL)
! 858: {
! 859: if (((*((struct_connecteur_sql *) (*s_objet).objet)).pid !=
! 860: getpid()) || (pthread_equal((*((struct_connecteur_sql *)
! 861: (*s_objet).objet)).tid, pthread_self()) == 0))
! 862: {
! 863: (*s_etat_processus).erreur_execution = d_ex_fichier_hors_contexte;
! 864:
! 865: liberation(s_etat_processus, s_objet);
! 866: return;
! 867: }
! 868:
! 869: l_element_courant = (*s_etat_processus).s_connecteurs_sql;
! 870: l_element_precedent = NULL;
! 871:
! 872: while(l_element_courant != NULL)
! 873: {
! 874: if (((*((struct_connecteur_sql *) (*(*l_element_courant).donnee)
! 875: .objet)).pid == getpid()) && (pthread_equal(
! 876: (*((struct_connecteur_sql *) (*(*l_element_courant).donnee)
! 877: .objet)).tid, pthread_self()) != 0) &&
! 878: (strcmp((*((struct_connecteur_sql *) (*(*l_element_courant)
! 879: .donnee).objet)).type, (*((struct_connecteur_sql *)
! 880: (*s_objet).objet)).type) == 0))
! 881: {
! 882: if (strcmp((*((struct_connecteur_sql *) (*s_objet).objet)).type,
! 883: "MYSQL") == 0)
! 884: {
! 885: # ifdef MYSQL_SUPPORT
! 886: if ((*((struct_connecteur_sql *) (*(*l_element_courant)
! 887: .donnee).objet)).descripteur.mysql ==
! 888: (*((struct_connecteur_sql *) (*s_objet).objet))
! 889: .descripteur.mysql)
! 890: {
! 891: drapeau = d_vrai;
! 892: }
! 893: else
! 894: {
! 895: drapeau = d_faux;
! 896: }
! 897: # else
! 898:
! 899: if ((*s_etat_processus).langue == 'F')
! 900: {
! 901: printf("+++Attention : Support de MySQL "
! 902: "non compilé !\n");
! 903: }
! 904: else
! 905: {
! 906: printf("+++Warning : MySQL support not available !\n");
! 907: }
! 908:
! 909: fflush(stdout);
! 910:
! 911: drapeau = d_faux;
! 912: # endif
! 913: }
! 914: else if (strcmp((*((struct_connecteur_sql *) (*s_objet).objet))
! 915: .type, "POSTGRESQL") == 0)
! 916: {
! 917: # ifdef POSTGRESQL_SUPPORT
! 918: if ((*((struct_connecteur_sql *) (*(*l_element_courant)
! 919: .donnee).objet)).descripteur.postgresql ==
! 920: (*((struct_connecteur_sql *) (*s_objet).objet))
! 921: .descripteur.postgresql)
! 922: {
! 923: drapeau = d_vrai;
! 924: }
! 925: else
! 926: {
! 927: drapeau = d_faux;
! 928: }
! 929:
! 930: # else
! 931:
! 932: if ((*s_etat_processus).langue == 'F')
! 933: {
! 934: printf("+++Attention : Support de PostgreSQL "
! 935: "non compilé !\n");
! 936: }
! 937: else
! 938: {
! 939: printf("+++Warning : PostgreSQL support "
! 940: "not available !\n");
! 941: }
! 942:
! 943: fflush(stdout);
! 944:
! 945: drapeau = d_faux;
! 946: # endif
! 947: }
! 948: else
! 949: {
! 950: BUG(1, printf("SQL type '%s' not allowed!",
! 951: (*((struct_connecteur_sql *) (*s_objet).objet))
! 952: .type));
! 953: return;
! 954: }
! 955:
! 956: if (drapeau == d_vrai)
! 957: {
! 958: if (l_element_precedent == NULL)
! 959: {
! 960: (*s_etat_processus).s_connecteurs_sql =
! 961: (*l_element_courant).suivant;
! 962: }
! 963: else if ((*l_element_courant).suivant == NULL)
! 964: {
! 965: (*l_element_precedent).suivant = NULL;
! 966: }
! 967: else
! 968: {
! 969: (*l_element_precedent).suivant =
! 970: (*l_element_courant).suivant;
! 971: }
! 972:
! 973: liberation(s_etat_processus, (*l_element_courant).donnee);
! 974: free(l_element_courant);
! 975:
! 976: break;
! 977: }
! 978: }
! 979:
! 980: l_element_precedent = l_element_courant;
! 981: l_element_courant = (*l_element_courant).suivant;
! 982: }
! 983:
! 984: sqlclose(s_objet);
! 985: }
! 986: else
! 987: {
! 988: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 989:
! 990: liberation(s_etat_processus, s_objet);
! 991: return;
! 992: }
! 993:
! 994: liberation(s_etat_processus, s_objet);
! 995: return;
! 996: }
! 997:
! 998:
! 999: /*
! 1000: ================================================================================
! 1001: Fonction 'smphrincr'
! 1002: ================================================================================
! 1003: Entrées :
! 1004: --------------------------------------------------------------------------------
! 1005: Sorties :
! 1006: --------------------------------------------------------------------------------
! 1007: Effets de bord : néant
! 1008: ================================================================================
! 1009: */
! 1010:
! 1011: void
! 1012: instruction_smphrincr(struct_processus *s_etat_processus)
! 1013: {
! 1014: struct_objet *s_objet_argument;
! 1015:
! 1016: (*s_etat_processus).erreur_execution = d_ex;
! 1017:
! 1018: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1019: {
! 1020: printf("\n SMPHRINCR ");
! 1021:
! 1022: if ((*s_etat_processus).langue == 'F')
! 1023: {
! 1024: printf("(incrémentation du sémaphore)\n\n");
! 1025: }
! 1026: else
! 1027: {
! 1028: printf("(semaphore incrementation)\n\n");
! 1029: }
! 1030:
! 1031: printf(" 1: %s\n", d_SPH);
! 1032: return;
! 1033: }
! 1034: else if ((*s_etat_processus).test_instruction == 'Y')
! 1035: {
! 1036: (*s_etat_processus).nombre_arguments = -1;
! 1037: return;
! 1038: }
! 1039:
! 1040: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1041: {
! 1042: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1043: {
! 1044: return;
! 1045: }
! 1046: }
! 1047:
! 1048: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1049: &s_objet_argument) == d_erreur)
! 1050: {
! 1051: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1052: return;
! 1053: }
! 1054:
! 1055: if ((*s_objet_argument).type == SPH)
! 1056: {
! 1057: if (sem_post((*((struct_semaphore *) (*s_objet_argument).objet))
! 1058: .semaphore) != 0)
! 1059: {
! 1060: (*s_etat_processus).erreur_execution = d_ex_semaphore;
! 1061:
! 1062: liberation(s_etat_processus, s_objet_argument);
! 1063: return;
! 1064: }
! 1065:
! 1066: liberation(s_etat_processus, s_objet_argument);
! 1067: }
! 1068: else
! 1069: {
! 1070: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1071:
! 1072: liberation(s_etat_processus, s_objet_argument);
! 1073: return;
! 1074: }
! 1075:
! 1076: return;
! 1077: }
! 1078:
! 1079:
! 1080: /*
! 1081: ================================================================================
! 1082: Fonction 'smphrdecr'
! 1083: ================================================================================
! 1084: Entrées :
! 1085: --------------------------------------------------------------------------------
! 1086: Sorties :
! 1087: --------------------------------------------------------------------------------
! 1088: Effets de bord : néant
! 1089: ================================================================================
! 1090: */
! 1091:
! 1092: void
! 1093: instruction_smphrdecr(struct_processus *s_etat_processus)
! 1094: {
! 1095: struct_objet *s_objet_argument;
! 1096:
! 1097: unsigned char *tampon;
! 1098:
! 1099: (*s_etat_processus).erreur_execution = d_ex;
! 1100:
! 1101: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1102: {
! 1103: printf("\n SMPHRDECR ");
! 1104:
! 1105: if ((*s_etat_processus).langue == 'F')
! 1106: {
! 1107: printf("(decrémentation du sémaphore)\n\n");
! 1108: }
! 1109: else
! 1110: {
! 1111: printf("(semaphore decrementation)\n\n");
! 1112: }
! 1113:
! 1114: printf(" 1: %s\n", d_SPH);
! 1115: return;
! 1116: }
! 1117: else if ((*s_etat_processus).test_instruction == 'Y')
! 1118: {
! 1119: (*s_etat_processus).nombre_arguments = -1;
! 1120: return;
! 1121: }
! 1122:
! 1123: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1124: {
! 1125: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1126: {
! 1127: return;
! 1128: }
! 1129: }
! 1130:
! 1131: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1132: &s_objet_argument) == d_erreur)
! 1133: {
! 1134: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1135: return;
! 1136: }
! 1137:
! 1138: if ((*s_objet_argument).type == SPH)
! 1139: {
! 1140: if ((*s_etat_processus).profilage == d_vrai)
! 1141: {
! 1142: if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
! 1143: == NULL)
! 1144: {
! 1145: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1146: return;
! 1147: }
! 1148:
! 1149: profilage(s_etat_processus, tampon);
! 1150: free(tampon);
! 1151:
! 1152: if ((*s_etat_processus).erreur_systeme != d_es)
! 1153: {
! 1154: return;
! 1155: }
! 1156: }
! 1157:
! 1158: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
! 1159: {
! 1160: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1161: return;
! 1162: }
! 1163:
! 1164: while(sem_wait((*((struct_semaphore *) (*s_objet_argument).objet))
! 1165: .semaphore) == -1)
! 1166: {
! 1167: if (errno != EINTR)
! 1168: {
! 1169: (*s_etat_processus).erreur_execution = d_ex_semaphore;
! 1170:
! 1171: if ((*s_etat_processus).profilage == d_vrai)
! 1172: {
! 1173: profilage(s_etat_processus, NULL);
! 1174: }
! 1175:
! 1176: liberation(s_etat_processus, s_objet_argument);
! 1177: return;
! 1178: }
! 1179: }
! 1180:
! 1181: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
! 1182: {
! 1183: if (errno != EINTR)
! 1184: {
! 1185: if ((*s_etat_processus).profilage == d_vrai)
! 1186: {
! 1187: profilage(s_etat_processus, NULL);
! 1188: }
! 1189:
! 1190: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1191: return;
! 1192: }
! 1193: }
! 1194:
! 1195: if ((*s_etat_processus).profilage == d_vrai)
! 1196: {
! 1197: profilage(s_etat_processus, NULL);
! 1198: }
! 1199:
! 1200: liberation(s_etat_processus, s_objet_argument);
! 1201: }
! 1202: else
! 1203: {
! 1204: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1205:
! 1206: liberation(s_etat_processus, s_objet_argument);
! 1207: return;
! 1208: }
! 1209:
! 1210: return;
! 1211: }
! 1212:
! 1213:
! 1214: /*
! 1215: ================================================================================
! 1216: Fonction 'smphrtrydecr'
! 1217: ================================================================================
! 1218: Entrées :
! 1219: --------------------------------------------------------------------------------
! 1220: Sorties :
! 1221: --------------------------------------------------------------------------------
! 1222: Effets de bord : néant
! 1223: ================================================================================
! 1224: */
! 1225:
! 1226: void
! 1227: instruction_smphrtrydecr(struct_processus *s_etat_processus)
! 1228: {
! 1229: struct_objet *s_objet_argument;
! 1230: struct_objet *s_objet_resultat;
! 1231:
! 1232: unsigned char *tampon;
! 1233:
! 1234: (*s_etat_processus).erreur_execution = d_ex;
! 1235:
! 1236: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1237: {
! 1238: printf("\n SMPHRTRYDECR ");
! 1239:
! 1240: if ((*s_etat_processus).langue == 'F')
! 1241: {
! 1242: printf("(essai de decrémentation du sémaphore)\n\n");
! 1243: }
! 1244: else
! 1245: {
! 1246: printf("(try to decremente semaphore)\n\n");
! 1247: }
! 1248:
! 1249: printf(" 1: %s\n", d_SPH);
! 1250: printf("-> 1: %s\n", d_INT);
! 1251: return;
! 1252: }
! 1253: else if ((*s_etat_processus).test_instruction == 'Y')
! 1254: {
! 1255: (*s_etat_processus).nombre_arguments = -1;
! 1256: return;
! 1257: }
! 1258:
! 1259: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1260: {
! 1261: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1262: {
! 1263: return;
! 1264: }
! 1265: }
! 1266:
! 1267: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1268: &s_objet_argument) == d_erreur)
! 1269: {
! 1270: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1271: return;
! 1272: }
! 1273:
! 1274: if ((*s_objet_argument).type == SPH)
! 1275: {
! 1276: if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
! 1277: {
! 1278: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1279: return;
! 1280: }
! 1281:
! 1282: if ((*s_etat_processus).profilage == d_vrai)
! 1283: {
! 1284: if ((tampon = formateur(s_etat_processus, 0, s_objet_argument))
! 1285: == NULL)
! 1286: {
! 1287: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1288: return;
! 1289: }
! 1290:
! 1291: profilage(s_etat_processus, tampon);
! 1292: free(tampon);
! 1293:
! 1294: if ((*s_etat_processus).erreur_systeme != d_es)
! 1295: {
! 1296: return;
! 1297: }
! 1298: }
! 1299:
! 1300: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0)
! 1301: {
! 1302: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1303: return;
! 1304: }
! 1305:
! 1306: (*((integer8 *) (*s_objet_resultat).objet)) = 0;
! 1307:
! 1308: while(sem_trywait((*((struct_semaphore *) (*s_objet_argument).objet))
! 1309: .semaphore) == -1)
! 1310: {
! 1311: switch(errno)
! 1312: {
! 1313: case EINTR :
! 1314: {
! 1315: break;
! 1316: }
! 1317:
! 1318: case EINVAL :
! 1319: {
! 1320: (*s_etat_processus).erreur_execution = d_ex_semaphore;
! 1321:
! 1322: if ((*s_etat_processus).profilage == d_vrai)
! 1323: {
! 1324: profilage(s_etat_processus, NULL);
! 1325: }
! 1326:
! 1327: liberation(s_etat_processus, s_objet_argument);
! 1328: return;
! 1329: }
! 1330:
! 1331: case EAGAIN :
! 1332: {
! 1333: (*((integer8 *) (*s_objet_resultat).objet)) = -1;
! 1334: break;
! 1335: }
! 1336: }
! 1337:
! 1338: if ((*((integer8 *) (*s_objet_resultat).objet)) != 0)
! 1339: {
! 1340: break;
! 1341: }
! 1342: }
! 1343:
! 1344: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1)
! 1345: {
! 1346: if (errno != EINTR)
! 1347: {
! 1348: if ((*s_etat_processus).profilage == d_vrai)
! 1349: {
! 1350: profilage(s_etat_processus, NULL);
! 1351: }
! 1352:
! 1353: (*s_etat_processus).erreur_systeme = d_es_processus;
! 1354: return;
! 1355: }
! 1356: }
! 1357:
! 1358: if ((*s_etat_processus).profilage == d_vrai)
! 1359: {
! 1360: profilage(s_etat_processus, NULL);
! 1361: }
! 1362:
! 1363: liberation(s_etat_processus, s_objet_argument);
! 1364: }
! 1365: else
! 1366: {
! 1367: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1368:
! 1369: liberation(s_etat_processus, s_objet_argument);
! 1370: return;
! 1371: }
! 1372:
! 1373: return;
! 1374: }
! 1375:
! 1376:
! 1377: /*
! 1378: ================================================================================
! 1379: Fonction 'smphrgetv'
! 1380: ================================================================================
! 1381: Entrées :
! 1382: --------------------------------------------------------------------------------
! 1383: Sorties :
! 1384: --------------------------------------------------------------------------------
! 1385: Effets de bord : néant
! 1386: ================================================================================
! 1387: */
! 1388:
! 1389: void
! 1390: instruction_smphrgetv(struct_processus *s_etat_processus)
! 1391: {
! 1392: int valeur;
! 1393:
! 1394: struct_objet *s_objet_argument;
! 1395: struct_objet *s_objet_resultat;
! 1396:
! 1397: (*s_etat_processus).erreur_execution = d_ex;
! 1398:
! 1399: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1400: {
! 1401: printf("\n SMPHRGETV ");
! 1402:
! 1403: if ((*s_etat_processus).langue == 'F')
! 1404: {
! 1405: printf("(valeur du sémaphore)\n\n");
! 1406: }
! 1407: else
! 1408: {
! 1409: printf("(semaphore value)\n\n");
! 1410: }
! 1411:
! 1412: printf(" 1: %s\n", d_SPH);
! 1413: return;
! 1414: }
! 1415: else if ((*s_etat_processus).test_instruction == 'Y')
! 1416: {
! 1417: (*s_etat_processus).nombre_arguments = -1;
! 1418: return;
! 1419: }
! 1420:
! 1421: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1422: {
! 1423: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1424: {
! 1425: return;
! 1426: }
! 1427: }
! 1428:
! 1429: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1430: &s_objet_argument) == d_erreur)
! 1431: {
! 1432: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1433: return;
! 1434: }
! 1435:
! 1436: if ((*s_objet_argument).type == SPH)
! 1437: {
! 1438: if ((s_objet_resultat = allocation(s_etat_processus, INT)) == NULL)
! 1439: {
! 1440: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1441:
! 1442: liberation(s_etat_processus, s_objet_argument);
! 1443: return;
! 1444: }
! 1445:
! 1446: if (sem_getvalue((*((struct_semaphore *) (*s_objet_argument).objet))
! 1447: .semaphore, &valeur) != 0)
! 1448: {
! 1449: (*s_etat_processus).erreur_execution = d_ex_semaphore;
! 1450:
! 1451: liberation(s_etat_processus, s_objet_argument);
! 1452: return;
! 1453: }
! 1454:
! 1455: (*((integer8 *) (*s_objet_resultat).objet)) = valeur;
! 1456:
! 1457: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1458: s_objet_resultat) == d_erreur)
! 1459: {
! 1460: return;
! 1461: }
! 1462:
! 1463: liberation(s_etat_processus, s_objet_argument);
! 1464: }
! 1465: else
! 1466: {
! 1467: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1468:
! 1469: liberation(s_etat_processus, s_objet_argument);
! 1470: return;
! 1471: }
! 1472:
! 1473: return;
! 1474: }
! 1475:
! 1476:
! 1477: /*
! 1478: ================================================================================
! 1479: Fonction 'svl'
! 1480: ================================================================================
! 1481: Entrées :
! 1482: --------------------------------------------------------------------------------
! 1483: Sorties :
! 1484: --------------------------------------------------------------------------------
! 1485: Effets de bord : néant
! 1486: ================================================================================
! 1487: */
! 1488:
! 1489: void
! 1490: instruction_svl(struct_processus *s_etat_processus)
! 1491: {
! 1492: struct_objet *s_objet_argument;
! 1493: struct_objet *s_objet_resultat;
! 1494:
! 1495: (*s_etat_processus).erreur_execution = d_ex;
! 1496:
! 1497: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1498: {
! 1499: printf("\n SVL ");
! 1500:
! 1501: if ((*s_etat_processus).langue == 'F')
! 1502: {
! 1503: printf("(valeurs singulières)\n\n");
! 1504: }
! 1505: else
! 1506: {
! 1507: printf("(singular values)\n\n");
! 1508: }
! 1509:
! 1510: printf(" 1: %s, %s, %s\n", d_MIN, d_MRL, d_MCX);
! 1511: printf("-> 1: %s\n", d_VRL);
! 1512: return;
! 1513: }
! 1514: else if ((*s_etat_processus).test_instruction == 'Y')
! 1515: {
! 1516: (*s_etat_processus).nombre_arguments = -1;
! 1517: return;
! 1518: }
! 1519:
! 1520: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1521: {
! 1522: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1523: {
! 1524: return;
! 1525: }
! 1526: }
! 1527:
! 1528: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1529: &s_objet_argument) == d_erreur)
! 1530: {
! 1531: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1532: return;
! 1533: }
! 1534:
! 1535: if (((*s_objet_argument).type == MIN) ||
! 1536: ((*s_objet_argument).type == MRL) ||
! 1537: ((*s_objet_argument).type == MCX))
! 1538: {
! 1539: if ((s_objet_resultat = allocation(s_etat_processus, VRL)) == NULL)
! 1540: {
! 1541: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1542: return;
! 1543: }
! 1544:
! 1545: valeurs_singulieres(s_etat_processus, (*s_objet_argument).objet,
! 1546: NULL, (*s_objet_resultat).objet, NULL);
! 1547:
! 1548: if ((*s_etat_processus).erreur_systeme != d_es)
! 1549: {
! 1550: return;
! 1551: }
! 1552:
! 1553: if (((*s_etat_processus).erreur_execution != d_ex) ||
! 1554: ((*s_etat_processus).exception != d_ep))
! 1555: {
! 1556: liberation(s_etat_processus, s_objet_resultat);
! 1557: liberation(s_etat_processus, s_objet_argument);
! 1558: return;
! 1559: }
! 1560:
! 1561: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1562: s_objet_resultat) == d_erreur)
! 1563: {
! 1564: return;
! 1565: }
! 1566: }
! 1567: else
! 1568: {
! 1569: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1570:
! 1571: liberation(s_etat_processus, s_objet_argument);
! 1572: return;
! 1573: }
! 1574:
! 1575: liberation(s_etat_processus, s_objet_argument);
! 1576:
! 1577: return;
! 1578: }
! 1579:
! 1580:
! 1581: /*
! 1582: ================================================================================
! 1583: Fonction 'svd'
! 1584: ================================================================================
! 1585: Entrées :
! 1586: --------------------------------------------------------------------------------
! 1587: Sorties :
! 1588: --------------------------------------------------------------------------------
! 1589: Effets de bord : néant
! 1590: ================================================================================
! 1591: */
! 1592:
! 1593: void
! 1594: instruction_svd(struct_processus *s_etat_processus)
! 1595: {
! 1596: struct_objet *s_objet_argument;
! 1597: struct_objet *s_objet_resultat_1;
! 1598: struct_objet *s_objet_resultat_2;
! 1599: struct_objet *s_objet_resultat_3;
! 1600:
! 1601: struct_vecteur s_vecteur;
! 1602:
! 1603: unsigned long i;
! 1604: unsigned long j;
! 1605:
! 1606: (*s_etat_processus).erreur_execution = d_ex;
! 1607:
! 1608: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1609: {
! 1610: printf("\n SVD ");
! 1611:
! 1612: if ((*s_etat_processus).langue == 'F')
! 1613: {
! 1614: printf("(décomposition en valeurs singulières)\n\n");
! 1615: }
! 1616: else
! 1617: {
! 1618: printf("(singular value decomposition)\n\n");
! 1619: }
! 1620:
! 1621: printf(" 1: %s, %s, %s\n", d_MIN, d_MRL, d_MCX);
! 1622: printf("-> 3: %s, %s\n", d_MRL, d_MCX);
! 1623: printf(" 2: %s, %s\n", d_MRL, d_MCX);
! 1624: printf(" 1: %s\n", d_VRL);
! 1625: return;
! 1626: }
! 1627: else if ((*s_etat_processus).test_instruction == 'Y')
! 1628: {
! 1629: (*s_etat_processus).nombre_arguments = -1;
! 1630: return;
! 1631: }
! 1632:
! 1633: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1634: {
! 1635: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1636: {
! 1637: return;
! 1638: }
! 1639: }
! 1640:
! 1641: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1642: &s_objet_argument) == d_erreur)
! 1643: {
! 1644: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1645: return;
! 1646: }
! 1647:
! 1648: if (((*s_objet_argument).type == MIN) ||
! 1649: ((*s_objet_argument).type == MRL))
! 1650: {
! 1651: if ((s_objet_resultat_1 = allocation(s_etat_processus, MRL)) == NULL)
! 1652: {
! 1653: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1654: return;
! 1655: }
! 1656:
! 1657: if ((s_objet_resultat_2 = allocation(s_etat_processus, MRL)) == NULL)
! 1658: {
! 1659: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1660: return;
! 1661: }
! 1662:
! 1663: if ((s_objet_resultat_3 = allocation(s_etat_processus, MRL)) == NULL)
! 1664: {
! 1665: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1666: return;
! 1667: }
! 1668:
! 1669: valeurs_singulieres(s_etat_processus, (*s_objet_argument).objet,
! 1670: (*s_objet_resultat_3).objet, &s_vecteur,
! 1671: (*s_objet_resultat_1).objet);
! 1672:
! 1673: if ((*s_etat_processus).erreur_systeme != d_es)
! 1674: {
! 1675: return;
! 1676: }
! 1677:
! 1678: if (((*s_etat_processus).erreur_execution != d_ex) ||
! 1679: ((*s_etat_processus).exception != d_ep))
! 1680: {
! 1681: liberation(s_etat_processus, s_objet_resultat_1);
! 1682: liberation(s_etat_processus, s_objet_resultat_2);
! 1683: liberation(s_etat_processus, s_objet_resultat_3);
! 1684: liberation(s_etat_processus, s_objet_argument);
! 1685: return;
! 1686: }
! 1687:
! 1688: (*((struct_matrice *) (*s_objet_resultat_2).objet)).nombre_colonnes =
! 1689: (*((struct_matrice *) (*s_objet_argument).objet))
! 1690: .nombre_colonnes;
! 1691: (*((struct_matrice *) (*s_objet_resultat_2).objet)).nombre_lignes =
! 1692: (*((struct_matrice *) (*s_objet_argument).objet))
! 1693: .nombre_lignes;
! 1694:
! 1695: if (((*((struct_matrice *) (*s_objet_resultat_2).objet)).tableau =
! 1696: malloc((*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1697: .nombre_lignes * sizeof(real8 *))) == NULL)
! 1698: {
! 1699: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1700: return;
! 1701: }
! 1702:
! 1703: for(i = 0; i < (*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1704: .nombre_lignes; i++)
! 1705: {
! 1706: if ((((real8 **) (*((struct_matrice *) (*s_objet_resultat_2)
! 1707: .objet)).tableau)[i] = malloc((*((struct_matrice *)
! 1708: (*s_objet_resultat_2).objet)).nombre_colonnes *
! 1709: sizeof(real8 *))) == NULL)
! 1710: {
! 1711: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1712: return;
! 1713: }
! 1714:
! 1715: for(j = 0; j < (*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1716: .nombre_colonnes; j++)
! 1717: {
! 1718: ((real8 **) (*((struct_matrice *) (*s_objet_resultat_2)
! 1719: .objet)).tableau)[i][j] = 0;
! 1720: }
! 1721: }
! 1722:
! 1723: for(i = 0; i < s_vecteur.taille; i++)
! 1724: {
! 1725: ((real8 **) (*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1726: .tableau)[i][i] = ((real8 *) (s_vecteur.tableau))[i];
! 1727: }
! 1728:
! 1729: free(s_vecteur.tableau);
! 1730:
! 1731: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1732: s_objet_resultat_3) == d_erreur)
! 1733: {
! 1734: return;
! 1735: }
! 1736:
! 1737: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1738: s_objet_resultat_2) == d_erreur)
! 1739: {
! 1740: return;
! 1741: }
! 1742:
! 1743: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1744: s_objet_resultat_1) == d_erreur)
! 1745: {
! 1746: return;
! 1747: }
! 1748: }
! 1749: else if ((*s_objet_argument).type == MCX)
! 1750: {
! 1751: if ((s_objet_resultat_1 = allocation(s_etat_processus, MCX)) == NULL)
! 1752: {
! 1753: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1754: return;
! 1755: }
! 1756:
! 1757: if ((s_objet_resultat_2 = allocation(s_etat_processus, MRL)) == NULL)
! 1758: {
! 1759: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1760: return;
! 1761: }
! 1762:
! 1763: if ((s_objet_resultat_3 = allocation(s_etat_processus, MCX)) == NULL)
! 1764: {
! 1765: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1766: return;
! 1767: }
! 1768:
! 1769: valeurs_singulieres(s_etat_processus, (*s_objet_argument).objet,
! 1770: (*s_objet_resultat_3).objet, &s_vecteur,
! 1771: (*s_objet_resultat_1).objet);
! 1772:
! 1773: if ((*s_etat_processus).erreur_systeme != d_es)
! 1774: {
! 1775: return;
! 1776: }
! 1777:
! 1778: if (((*s_etat_processus).erreur_execution != d_ex) ||
! 1779: ((*s_etat_processus).exception != d_ep))
! 1780: {
! 1781: liberation(s_etat_processus, s_objet_resultat_1);
! 1782: liberation(s_etat_processus, s_objet_resultat_2);
! 1783: liberation(s_etat_processus, s_objet_resultat_3);
! 1784: liberation(s_etat_processus, s_objet_argument);
! 1785: return;
! 1786: }
! 1787:
! 1788: (*((struct_matrice *) (*s_objet_resultat_2).objet)).nombre_colonnes =
! 1789: (*((struct_matrice *) (*s_objet_argument).objet))
! 1790: .nombre_colonnes;
! 1791: (*((struct_matrice *) (*s_objet_resultat_2).objet)).nombre_lignes =
! 1792: (*((struct_matrice *) (*s_objet_argument).objet))
! 1793: .nombre_lignes;
! 1794:
! 1795: if (((*((struct_matrice *) (*s_objet_resultat_2).objet)).tableau =
! 1796: malloc((*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1797: .nombre_lignes * sizeof(real8 *))) == NULL)
! 1798: {
! 1799: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1800: return;
! 1801: }
! 1802:
! 1803: for(i = 0; i < (*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1804: .nombre_lignes; i++)
! 1805: {
! 1806: if ((((real8 **) (*((struct_matrice *) (*s_objet_resultat_2)
! 1807: .objet)).tableau)[i] = malloc((*((struct_matrice *)
! 1808: (*s_objet_resultat_2).objet)).nombre_colonnes *
! 1809: sizeof(real8 *))) == NULL)
! 1810: {
! 1811: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
! 1812: return;
! 1813: }
! 1814:
! 1815: for(j = 0; j < (*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1816: .nombre_colonnes; j++)
! 1817: {
! 1818: ((real8 **) (*((struct_matrice *) (*s_objet_resultat_2)
! 1819: .objet)).tableau)[i][j] = 0;
! 1820: }
! 1821: }
! 1822:
! 1823: for(i = 0; i < s_vecteur.taille; i++)
! 1824: {
! 1825: ((real8 **) (*((struct_matrice *) (*s_objet_resultat_2).objet))
! 1826: .tableau)[i][i] = ((real8 *) (s_vecteur.tableau))[i];
! 1827: }
! 1828:
! 1829: free(s_vecteur.tableau);
! 1830:
! 1831: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1832: s_objet_resultat_3) == d_erreur)
! 1833: {
! 1834: return;
! 1835: }
! 1836:
! 1837: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1838: s_objet_resultat_2) == d_erreur)
! 1839: {
! 1840: return;
! 1841: }
! 1842:
! 1843: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1844: s_objet_resultat_1) == d_erreur)
! 1845: {
! 1846: return;
! 1847: }
! 1848: }
! 1849: else
! 1850: {
! 1851: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1852:
! 1853: liberation(s_etat_processus, s_objet_argument);
! 1854: return;
! 1855: }
! 1856:
! 1857: liberation(s_etat_processus, s_objet_argument);
! 1858: return;
! 1859: }
! 1860:
! 1861:
! 1862: /*
! 1863: ================================================================================
! 1864: Fonction 'swapcntxt'
! 1865: ================================================================================
! 1866: Entrées :
! 1867: --------------------------------------------------------------------------------
! 1868: Sorties :
! 1869: --------------------------------------------------------------------------------
! 1870: Effets de bord : néant
! 1871: ================================================================================
! 1872: */
! 1873:
! 1874: void
! 1875: instruction_swapcntxt(struct_processus *s_etat_processus)
! 1876: {
! 1877: integer8 i;
! 1878: integer8 registre_taille;
! 1879:
! 1880: struct_liste_chainee *l_element_courant;
! 1881: struct_liste_chainee *l_element_courant_taille;
! 1882: struct_liste_chainee *registre;
! 1883:
! 1884: struct_objet *s_objet_argument;
! 1885:
! 1886: (*s_etat_processus).erreur_execution = d_ex;
! 1887:
! 1888: if ((*s_etat_processus).affichage_arguments == 'Y')
! 1889: {
! 1890: printf("\n SWAPCNTXT ");
! 1891:
! 1892: if ((*s_etat_processus).langue == 'F')
! 1893: {
! 1894: printf("(échange de contextes)\n\n");
! 1895: }
! 1896: else
! 1897: {
! 1898: printf("(swap contexts)\n\n");
! 1899: }
! 1900:
! 1901: printf(" 1: %s\n", d_INT);
! 1902: return;
! 1903: }
! 1904: else if ((*s_etat_processus).test_instruction == 'Y')
! 1905: {
! 1906: (*s_etat_processus).nombre_arguments = -1;
! 1907: return;
! 1908: }
! 1909:
! 1910: if (test_cfsf(s_etat_processus, 31) == d_vrai)
! 1911: {
! 1912: if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
! 1913: {
! 1914: return;
! 1915: }
! 1916: }
! 1917:
! 1918: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
! 1919: &s_objet_argument) == d_erreur)
! 1920: {
! 1921: (*s_etat_processus).erreur_execution = d_ex_manque_argument;
! 1922: return;
! 1923: }
! 1924:
! 1925: if ((*s_objet_argument).type == INT)
! 1926: {
! 1927: l_element_courant = (*s_etat_processus).l_base_pile_contextes;
! 1928: l_element_courant_taille = (*s_etat_processus)
! 1929: .l_base_pile_taille_contextes;
! 1930:
! 1931: i = (*((integer8 *) (*s_objet_argument).objet));
! 1932:
! 1933: while((l_element_courant != NULL) && (l_element_courant_taille != NULL))
! 1934: {
! 1935: i--;
! 1936:
! 1937: if (i == 0)
! 1938: {
! 1939: break;
! 1940: }
! 1941:
! 1942: l_element_courant = (*l_element_courant).suivant;
! 1943: l_element_courant_taille = (*l_element_courant_taille).suivant;
! 1944: }
! 1945:
! 1946: if ((l_element_courant == NULL) || (l_element_courant_taille == NULL))
! 1947: {
! 1948: liberation(s_etat_processus, s_objet_argument);
! 1949:
! 1950: (*s_etat_processus).erreur_execution = d_ex_contexte;
! 1951: return;
! 1952: }
! 1953:
! 1954: if ((*(*l_element_courant).donnee).type != LST)
! 1955: {
! 1956: (*s_etat_processus).erreur_systeme = d_es_contexte;
! 1957: return;
! 1958: }
! 1959:
! 1960: if ((*(*l_element_courant_taille).donnee).type != INT)
! 1961: {
! 1962: (*s_etat_processus).erreur_systeme = d_es_contexte;
! 1963: return;
! 1964: }
! 1965:
! 1966: registre = (*s_etat_processus).l_base_pile;
! 1967: registre_taille = (*s_etat_processus).hauteur_pile_operationnelle;
! 1968:
! 1969: (*s_etat_processus).l_base_pile = (*(*l_element_courant).donnee).objet;
! 1970: (*s_etat_processus).hauteur_pile_operationnelle =
! 1971: (*((integer8 *) (*(*l_element_courant_taille).donnee).objet));
! 1972:
! 1973: (*(*l_element_courant).donnee).objet = registre;
! 1974: (*((integer8 *) (*(*l_element_courant_taille).donnee).objet)) =
! 1975: registre_taille;
! 1976: }
! 1977: else
! 1978: {
! 1979: liberation(s_etat_processus, s_objet_argument);
! 1980:
! 1981: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
! 1982: return;
! 1983: }
! 1984:
! 1985: liberation(s_etat_processus, s_objet_argument);
! 1986: }
! 1987:
! 1988: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>