![]() ![]() | ![]() |
Passage de la branche 4.1 en branche stable.
1: /* 2: ================================================================================ 3: RPL/2 (R) version 4.1.0 4: Copyright (C) 1989-2011 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 'sort' 29: ================================================================================ 30: Entrées : 31: -------------------------------------------------------------------------------- 32: Sorties : 33: -------------------------------------------------------------------------------- 34: Effets de bord : néant 35: ================================================================================ 36: */ 37: 38: void 39: instruction_sort(struct_processus *s_etat_processus) 40: { 41: integer8 i; 42: integer8 j; 43: integer8 nombre_elements; 44: 45: logical1 condition; 46: logical1 inversion; 47: logical1 presence_nom; 48: logical1 terminaison_boucle_1; 49: logical1 terminaison_boucle_2; 50: logical1 terminaison_boucle_3; 51: logical1 variable_partagee; 52: 53: struct_liste_chainee *l_element_courant; 54: struct_liste_chainee *l_element_precedent; 55: struct_liste_chainee *l_element_tampon; 56: 57: struct_objet *s_objet_copie; 58: struct_objet *s_objet_critere; 59: struct_objet *s_objet_liste; 60: struct_objet *s_objet_registre; 61: struct_objet *s_objet_test; 62: 63: signed long indice_i; 64: signed long indice_j; 65: signed long indice_k; 66: signed long indice_l; 67: 68: unsigned long ecartement; 69: 70: (*s_etat_processus).erreur_execution = d_ex; 71: 72: if ((*s_etat_processus).affichage_arguments == 'Y') 73: { 74: printf("\n SORT "); 75: 76: if ((*s_etat_processus).langue == 'F') 77: { 78: printf("(trie une liste selon un critère paramétrable)\n\n"); 79: } 80: else 81: { 82: printf("(sort a list)\n\n"); 83: } 84: 85: printf(" 2: %s\n", d_LST); 86: printf(" 1: %s\n", d_RPN); 87: printf("-> 1: %s\n\n", d_LST); 88: 89: printf(" 2: %s\n", d_TAB); 90: printf(" 1: %s\n", d_RPN); 91: printf("-> 1: %s\n\n", d_LST); 92: 93: printf(" 2: %s\n", d_NOM); 94: printf(" 1: %s\n", d_RPN); 95: 96: return; 97: } 98: else if ((*s_etat_processus).test_instruction == 'Y') 99: { 100: (*s_etat_processus).nombre_arguments = -1; 101: return; 102: } 103: 104: if (test_cfsf(s_etat_processus, 31) == d_vrai) 105: { 106: if (empilement_pile_last(s_etat_processus, 2) == d_erreur) 107: { 108: return; 109: } 110: } 111: 112: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 113: &s_objet_critere) == d_erreur) 114: { 115: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 116: return; 117: } 118: 119: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 120: &s_objet_liste) == d_erreur) 121: { 122: liberation(s_etat_processus, s_objet_critere); 123: 124: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 125: return; 126: } 127: 128: variable_partagee = d_faux; 129: 130: if ((*s_objet_liste).type == NOM) 131: { 132: if (recherche_variable(s_etat_processus, (*((struct_nom *) 133: (*s_objet_liste).objet)).nom) == d_faux) 134: { 135: (*s_etat_processus).erreur_systeme = d_es; 136: (*s_etat_processus).erreur_execution = d_ex_variable_non_definie; 137: 138: liberation(s_etat_processus, s_objet_critere); 139: liberation(s_etat_processus, s_objet_liste); 140: 141: return; 142: } 143: 144: if ((*(*s_etat_processus).pointeur_variable_courante) 145: .variable_verrouillee == d_vrai) 146: { 147: (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee; 148: 149: liberation(s_etat_processus, s_objet_critere); 150: liberation(s_etat_processus, s_objet_liste); 151: 152: return; 153: } 154: 155: if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL) 156: { 157: if (pthread_mutex_lock(&((*(*s_etat_processus) 158: .s_liste_variables_partagees).mutex)) != 0) 159: { 160: (*s_etat_processus).erreur_systeme = d_es_processus; 161: return; 162: } 163: 164: if (recherche_variable_partagee(s_etat_processus, 165: (*(*s_etat_processus).pointeur_variable_courante).nom, 166: (*(*s_etat_processus).pointeur_variable_courante) 167: .variable_partagee, (*(*s_etat_processus) 168: .pointeur_variable_courante).origine) == d_faux) 169: { 170: if (pthread_mutex_unlock(&((*(*s_etat_processus) 171: .s_liste_variables_partagees).mutex)) != 0) 172: { 173: (*s_etat_processus).erreur_systeme = d_es_processus; 174: return; 175: } 176: 177: (*s_etat_processus).erreur_execution = 178: d_ex_erreur_type_argument; 179: 180: liberation(s_etat_processus, s_objet_critere); 181: liberation(s_etat_processus, s_objet_liste); 182: 183: return; 184: } 185: 186: if (((*(*(*s_etat_processus).s_liste_variables_partagees) 187: .table[(*(*s_etat_processus).s_liste_variables_partagees) 188: .position_variable].objet).type != LST) && 189: ((*(*(*s_etat_processus).s_liste_variables_partagees) 190: .table[(*(*s_etat_processus).s_liste_variables_partagees) 191: .position_variable].objet).type != TBL)) 192: { 193: if (pthread_mutex_unlock(&((*(*s_etat_processus) 194: .s_liste_variables_partagees).mutex)) != 0) 195: { 196: (*s_etat_processus).erreur_systeme = d_es_processus; 197: return; 198: } 199: 200: (*s_etat_processus).erreur_execution = 201: d_ex_erreur_type_argument; 202: 203: liberation(s_etat_processus, s_objet_critere); 204: liberation(s_etat_processus, s_objet_liste); 205: 206: return; 207: } 208: 209: liberation(s_etat_processus, s_objet_liste); 210: 211: s_objet_liste = (*(*s_etat_processus).s_liste_variables_partagees) 212: .table[(*(*s_etat_processus).s_liste_variables_partagees) 213: .position_variable].objet; 214: 215: if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste, 216: 'N')) == NULL) 217: { 218: if (pthread_mutex_unlock(&((*(*s_etat_processus) 219: .s_liste_variables_partagees).mutex)) != 0) 220: { 221: (*s_etat_processus).erreur_systeme = d_es_processus; 222: return; 223: } 224: 225: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 226: return; 227: } 228: 229: variable_partagee = d_vrai; 230: } 231: else 232: { 233: if (((*(*(*s_etat_processus).pointeur_variable_courante).objet) 234: .type != LST) && ((*(*(*s_etat_processus) 235: .pointeur_variable_courante).objet).type != TBL)) 236: { 237: (*s_etat_processus).erreur_execution = 238: d_ex_erreur_type_argument; 239: 240: liberation(s_etat_processus, s_objet_critere); 241: liberation(s_etat_processus, s_objet_liste); 242: 243: return; 244: } 245: 246: liberation(s_etat_processus, s_objet_liste); 247: 248: s_objet_liste = (*(*s_etat_processus).pointeur_variable_courante) 249: .objet; 250: 251: if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste, 252: 'N')) == NULL) 253: { 254: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 255: return; 256: } 257: } 258: 259: liberation(s_etat_processus, s_objet_liste); 260: s_objet_liste = s_objet_copie; 261: (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_liste; 262: presence_nom = d_vrai; 263: } 264: else 265: { 266: if ((s_objet_copie = copie_objet(s_etat_processus, s_objet_liste, 'N')) 267: == NULL) 268: { 269: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 270: return; 271: } 272: 273: liberation(s_etat_processus, s_objet_liste); 274: s_objet_liste = s_objet_copie; 275: presence_nom = d_faux; 276: } 277: 278: if (((*s_objet_liste).type == LST) && 279: ((*s_objet_critere).type == RPN)) 280: { 281: /* 282: * Tri bulle de la liste chaînée. On se contente d'un tri bulle 283: * car on travaille sur une liste chaînée et non sur un tableau 284: * sur lequel on pourrait accéder directement aux données grâce à 285: * leur indice. 286: */ 287: 288: nombre_elements = 0; 289: l_element_courant = (*s_objet_liste).objet; 290: 291: while(l_element_courant != NULL) 292: { 293: l_element_courant = (*l_element_courant).suivant; 294: nombre_elements++; 295: } 296: 297: // Si la liste est vide, on considère qu'elle est triée. 298: // De la même manière, on considère qu'une liste d'un 299: // seul élément est toujours triée. 300: 301: if (nombre_elements > 1) 302: { 303: j = nombre_elements; 304: 305: do 306: { 307: inversion = d_faux; 308: 309: l_element_courant = (*s_objet_liste).objet; 310: l_element_precedent = NULL; 311: 312: for(i = 0; i < j - 1; i++) 313: { 314: // Test des éléments adjacents. Pour cela, on 315: // empile les deux éléments adjacents dans la pile dans 316: // l'ordre [i] [i+1] et on évalue le critère d'ordre. 317: 318: if ((s_objet_copie = copie_objet(s_etat_processus, 319: (*l_element_courant).donnee, 'P')) == NULL) 320: { 321: (*s_etat_processus).erreur_systeme = 322: d_es_allocation_memoire; 323: return; 324: } 325: 326: if (empilement(s_etat_processus, 327: &((*s_etat_processus).l_base_pile), 328: s_objet_copie) == d_erreur) 329: { 330: return; 331: } 332: 333: if ((s_objet_copie = copie_objet(s_etat_processus, 334: (*(*l_element_courant) 335: .suivant).donnee, 'P')) == NULL) 336: { 337: (*s_etat_processus).erreur_systeme = 338: d_es_allocation_memoire; 339: return; 340: } 341: 342: if (empilement(s_etat_processus, 343: &((*s_etat_processus).l_base_pile), 344: s_objet_copie) == d_erreur) 345: { 346: return; 347: } 348: 349: if (evaluation(s_etat_processus, s_objet_critere, 'N') 350: == d_erreur) 351: { 352: liberation(s_etat_processus, s_objet_critere); 353: liberation(s_etat_processus, s_objet_liste); 354: 355: return; 356: } 357: 358: if (depilement(s_etat_processus, 359: &((*s_etat_processus).l_base_pile), &s_objet_test) 360: == d_erreur) 361: { 362: liberation(s_etat_processus, s_objet_critere); 363: liberation(s_etat_processus, s_objet_liste); 364: 365: (*s_etat_processus).erreur_execution = 366: d_ex_manque_argument; 367: return; 368: } 369: 370: if ((*s_objet_test).type == INT) 371: { 372: condition = ((*((integer8 *) (*s_objet_test).objet)) 373: == 0) ? d_faux : d_vrai; 374: } 375: else if ((*s_objet_test).type == REL) 376: { 377: condition = ((*((real8 *) (*s_objet_test).objet)) 378: == 0) ? d_faux : d_vrai; 379: } 380: else 381: { 382: liberation(s_etat_processus, s_objet_critere); 383: liberation(s_etat_processus, s_objet_liste); 384: liberation(s_etat_processus, s_objet_test); 385: 386: (*s_etat_processus).erreur_execution = 387: d_ex_erreur_type_argument; 388: return; 389: } 390: 391: liberation(s_etat_processus, s_objet_test); 392: 393: if (condition == d_faux) 394: { 395: // On échange les deux éléments adjacents 396: 397: inversion = d_vrai; 398: 399: if (l_element_precedent == NULL) 400: { 401: // Échange des deux premiers éléments 402: // de la liste. 403: 404: l_element_tampon = (*(*l_element_courant) 405: .suivant).suivant; 406: (*s_objet_liste).objet = (*l_element_courant) 407: .suivant; 408: (*((struct_liste_chainee *) (*s_objet_liste) 409: .objet)).suivant = l_element_courant; 410: (*l_element_courant).suivant = 411: l_element_tampon; 412: l_element_courant = (*s_objet_liste).objet; 413: } 414: else 415: { 416: // Échange de deux éléments quelconques de la 417: // liste. 418: 419: l_element_tampon = (*l_element_courant).suivant; 420: (*l_element_courant).suivant = 421: (*(*l_element_courant).suivant).suivant; 422: (*l_element_precedent).suivant = l_element_tampon; 423: (*l_element_tampon).suivant = l_element_courant; 424: 425: l_element_courant = l_element_tampon; 426: } 427: } 428: 429: l_element_precedent = l_element_courant; 430: l_element_courant = (*l_element_courant).suivant; 431: } 432: 433: j--; 434: } while(inversion != d_faux); 435: } 436: } 437: else if (((*s_objet_liste).type == TBL) && 438: ((*s_objet_critere).type == RPN)) 439: { 440: /* 441: * Tri Shell-Metzner d'une table 442: */ 443: 444: ecartement = (*((struct_tableau *) (*s_objet_liste).objet)) 445: .nombre_elements; 446: terminaison_boucle_1 = d_faux; 447: 448: do 449: { 450: ecartement = ecartement / 2; 451: 452: if (ecartement >= 1) 453: { 454: indice_j = 0; 455: indice_k = (*((struct_tableau *) (*s_objet_liste).objet)) 456: .nombre_elements - ecartement; 457: terminaison_boucle_2 = d_faux; 458: 459: do 460: { 461: indice_i = indice_j; 462: terminaison_boucle_3 = d_faux; 463: 464: do 465: { 466: indice_l = indice_i + ecartement; 467: 468: if ((indice_i > 0) && (indice_l > 0)) 469: { 470: if ((s_objet_copie = copie_objet(s_etat_processus, 471: (*((struct_tableau *) (*s_objet_liste) 472: .objet)).elements[indice_i - 1], 'P')) 473: == NULL) 474: { 475: (*s_etat_processus).erreur_systeme = 476: d_es_allocation_memoire; 477: return; 478: } 479: 480: if (empilement(s_etat_processus, 481: &((*s_etat_processus).l_base_pile), 482: s_objet_copie) == d_erreur) 483: { 484: return; 485: } 486: 487: if ((s_objet_copie = copie_objet(s_etat_processus, 488: (*((struct_tableau *) (*s_objet_liste) 489: .objet)).elements[indice_l - 1], 'P')) 490: == NULL) 491: { 492: (*s_etat_processus).erreur_systeme = 493: d_es_allocation_memoire; 494: return; 495: } 496: 497: if (empilement(s_etat_processus, 498: &((*s_etat_processus).l_base_pile), 499: s_objet_copie) == d_erreur) 500: { 501: return; 502: } 503: 504: if (evaluation(s_etat_processus, s_objet_critere, 505: 'N') == d_erreur) 506: { 507: liberation(s_etat_processus, s_objet_critere); 508: liberation(s_etat_processus, s_objet_liste); 509: 510: return; 511: } 512: 513: if (depilement(s_etat_processus, 514: &((*s_etat_processus).l_base_pile), 515: &s_objet_test) == d_erreur) 516: { 517: liberation(s_etat_processus, s_objet_critere); 518: liberation(s_etat_processus, s_objet_liste); 519: 520: (*s_etat_processus).erreur_execution = 521: d_ex_manque_argument; 522: return; 523: } 524: 525: if ((*s_objet_test).type == INT) 526: { 527: condition = ((*((integer8 *) (*s_objet_test) 528: .objet)) == 0) ? d_faux : d_vrai; 529: } 530: else if ((*s_objet_test).type == REL) 531: { 532: condition = ((*((real8 *) (*s_objet_test) 533: .objet)) == 0) ? d_faux : d_vrai; 534: } 535: else 536: { 537: liberation(s_etat_processus, s_objet_critere); 538: liberation(s_etat_processus, s_objet_liste); 539: liberation(s_etat_processus, s_objet_test); 540: 541: (*s_etat_processus).erreur_execution = 542: d_ex_erreur_type_argument; 543: return; 544: } 545: 546: liberation(s_etat_processus, s_objet_test); 547: 548: if (condition == d_faux) 549: { 550: s_objet_registre = 551: (*((struct_tableau *) 552: (*s_objet_liste).objet)).elements 553: [indice_i - 1]; 554: (*((struct_tableau *) (*s_objet_liste).objet)) 555: .elements[indice_i - 1] = 556: (*((struct_tableau *) (*s_objet_liste) 557: .objet)).elements[indice_l - 1]; 558: (*((struct_tableau *) (*s_objet_liste) 559: .objet)).elements[indice_l - 1] = 560: s_objet_registre; 561: 562: indice_i -= ecartement; 563: 564: if (indice_i < 1) 565: { 566: terminaison_boucle_3 = d_vrai; 567: } 568: } 569: else 570: { 571: terminaison_boucle_3 = d_vrai; 572: } 573: } 574: else 575: { 576: terminaison_boucle_3 = d_vrai; 577: } 578: } while(terminaison_boucle_3 == d_faux); 579: 580: indice_j++; 581: 582: if (indice_j > indice_k) 583: { 584: terminaison_boucle_2 = d_vrai; 585: } 586: } while(terminaison_boucle_2 == d_faux); 587: } 588: else 589: { 590: terminaison_boucle_1 = d_vrai; 591: } 592: } while(terminaison_boucle_1 == d_faux); 593: } 594: else 595: { 596: if (pthread_mutex_unlock(&((*(*s_etat_processus) 597: .s_liste_variables_partagees).mutex)) != 0) 598: { 599: (*s_etat_processus).erreur_systeme = d_es_processus; 600: return; 601: } 602: 603: liberation(s_etat_processus, s_objet_liste); 604: liberation(s_etat_processus, s_objet_critere); 605: 606: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 607: return; 608: } 609: 610: if (presence_nom == d_faux) 611: { 612: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 613: s_objet_liste) == d_erreur) 614: { 615: return; 616: } 617: } 618: else 619: { 620: if (variable_partagee == d_vrai) 621: { 622: (*(*s_etat_processus).s_liste_variables_partagees) 623: .table[(*(*s_etat_processus).s_liste_variables_partagees) 624: .position_variable].objet = s_objet_liste; 625: 626: if (pthread_mutex_unlock(&((*(*s_etat_processus) 627: .s_liste_variables_partagees).mutex)) != 0) 628: { 629: (*s_etat_processus).erreur_systeme = d_es_processus; 630: return; 631: } 632: } 633: } 634: 635: liberation(s_etat_processus, s_objet_critere); 636: 637: return; 638: } 639: 640: 641: /* 642: ================================================================================ 643: Fonction 'save' 644: ================================================================================ 645: Entrées : structure processus 646: -------------------------------------------------------------------------------- 647: Sorties : 648: -------------------------------------------------------------------------------- 649: Effets de bord : néant 650: ================================================================================ 651: */ 652: 653: void 654: instruction_save(struct_processus *s_etat_processus) 655: { 656: struct_objet *s_objet_1; 657: struct_objet *s_objet_2; 658: 659: struct_variable s_variable; 660: 661: (*s_etat_processus).erreur_execution = d_ex; 662: 663: if ((*s_etat_processus).affichage_arguments == 'Y') 664: { 665: printf("\n SAVE "); 666: 667: if ((*s_etat_processus).langue == 'F') 668: { 669: printf("(affecte un objet à une variable globale)\n\n"); 670: } 671: else 672: { 673: printf("(store an object in a global variable)\n\n"); 674: } 675: 676: printf(" 2: %s, %s, %s, %s, %s, %s,\n" 677: " %s, %s, %s, %s, %s,\n" 678: " %s, %s, %s, %s, %s,\n" 679: " %s, %s, %s, %s,\n" 680: " %s, %s\n", 681: d_INT, d_REL, d_CPL, d_VIN, d_VRL, d_VCX, d_MIN, d_MRL, d_MCX, 682: d_TAB, d_BIN, d_NOM, d_CHN, d_LST, d_ALG, d_RPN, d_FCH, d_SCK, 683: d_SQL, d_SLB, d_PRC, d_MTX); 684: printf(" 1: %s\n", d_NOM); 685: 686: return; 687: } 688: else if ((*s_etat_processus).test_instruction == 'Y') 689: { 690: (*s_etat_processus).nombre_arguments = -1; 691: return; 692: } 693: 694: if (test_cfsf(s_etat_processus, 31) == d_vrai) 695: { 696: if (empilement_pile_last(s_etat_processus, 2) == d_erreur) 697: { 698: return; 699: } 700: } 701: 702: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 703: &s_objet_1) == d_erreur) 704: { 705: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 706: return; 707: } 708: 709: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 710: &s_objet_2) == d_erreur) 711: { 712: liberation(s_etat_processus, s_objet_1); 713: 714: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 715: return; 716: } 717: 718: if ((*s_objet_1).type != NOM) 719: { 720: liberation(s_etat_processus, s_objet_1); 721: liberation(s_etat_processus, s_objet_2); 722: 723: (*s_etat_processus).erreur_execution = d_ex_nom_invalide; 724: return; 725: } 726: 727: if (recherche_variable_globale(s_etat_processus, (*((struct_nom *) 728: (*s_objet_1).objet)).nom) == d_vrai) 729: { 730: /* 731: * Une variable est accessible. 732: */ 733: 734: if ((*(*s_etat_processus).pointeur_variable_courante) 735: .variable_verrouillee == d_vrai) 736: { 737: liberation(s_etat_processus, s_objet_1); 738: liberation(s_etat_processus, s_objet_2); 739: 740: (*s_etat_processus).erreur_execution = d_ex_variable_verrouillee; 741: return; 742: } 743: 744: if ((*(*s_etat_processus).pointeur_variable_courante).objet == NULL) 745: { 746: liberation(s_etat_processus, s_objet_1); 747: liberation(s_etat_processus, s_objet_2); 748: 749: (*s_etat_processus).erreur_execution = d_ex_variable_partagee; 750: return; 751: } 752: 753: liberation(s_etat_processus, 754: (*(*s_etat_processus).pointeur_variable_courante).objet); 755: (*(*s_etat_processus).pointeur_variable_courante).objet = s_objet_2; 756: } 757: else 758: { 759: /* 760: * Aucune variable n'est accessible (ni locale, ni globale). 761: */ 762: 763: if ((s_variable.nom = malloc((strlen((*((struct_nom *) 764: (*s_objet_1).objet)).nom) + 1) * sizeof(unsigned char))) 765: == NULL) 766: { 767: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 768: return; 769: } 770: 771: strcpy(s_variable.nom, (*((struct_nom *) (*s_objet_1).objet)).nom); 772: s_variable.niveau = 1; 773: 774: /* 775: * Le niveau 0 correspond aux définitions. Les variables 776: * commencent à 1 car elles sont toujours incluses dans 777: * une définition. 778: */ 779: 780: s_variable.objet = s_objet_2; 781: 782: if (creation_variable(s_etat_processus, &s_variable, 'V', 'P') 783: == d_erreur) 784: { 785: return; 786: } 787: 788: (*s_etat_processus).erreur_systeme = d_es; 789: } 790: 791: liberation(s_etat_processus, s_objet_1); 792: 793: return; 794: } 795: 796: 797: /* 798: ================================================================================ 799: Fonction 'suspend' 800: ================================================================================ 801: Entrées : structure processus 802: -------------------------------------------------------------------------------- 803: Sorties : 804: -------------------------------------------------------------------------------- 805: Effets de bord : néant 806: ================================================================================ 807: */ 808: 809: void 810: instruction_suspend(struct_processus *s_etat_processus) 811: { 812: sigset_t masque; 813: 814: (*s_etat_processus).erreur_execution = d_ex; 815: 816: if ((*s_etat_processus).affichage_arguments == 'Y') 817: { 818: printf("\n SUSPEND "); 819: 820: if ((*s_etat_processus).langue == 'F') 821: { 822: printf("(attend un signal SIGCONT)\n\n"); 823: printf(" Aucun argument\n"); 824: } 825: else 826: { 827: printf("(wait for SIGCONT signal)\n\n"); 828: printf(" No argument\n"); 829: } 830: 831: return; 832: } 833: else if ((*s_etat_processus).test_instruction == 'Y') 834: { 835: (*s_etat_processus).nombre_arguments = -1; 836: return; 837: } 838: 839: if (test_cfsf(s_etat_processus, 31) == d_vrai) 840: { 841: if (empilement_pile_last(s_etat_processus, 0) == d_erreur) 842: { 843: return; 844: } 845: } 846: 847: if (sigfillset(&masque) != 0) 848: { 849: (*s_etat_processus).erreur_systeme = d_es_processus; 850: return; 851: } 852: 853: if (sigdelset(&masque, SIGCONT) != 0) 854: { 855: (*s_etat_processus).erreur_systeme = d_es_processus; 856: return; 857: } 858: 859: if (sigdelset(&masque, SIGFSTOP) != 0) 860: { 861: (*s_etat_processus).erreur_systeme = d_es_processus; 862: return; 863: } 864: 865: if (sigdelset(&masque, SIGFABORT) != 0) 866: { 867: (*s_etat_processus).erreur_systeme = d_es_processus; 868: return; 869: } 870: 871: if (sigdelset(&masque, SIGURG) != 0) 872: { 873: (*s_etat_processus).erreur_systeme = d_es_processus; 874: return; 875: } 876: 877: if (sigdelset(&masque, SIGALRM) != 0) 878: { 879: (*s_etat_processus).erreur_systeme = d_es_processus; 880: return; 881: } 882: 883: if ((*s_etat_processus).profilage == d_vrai) 884: { 885: profilage(s_etat_processus, "Suspend"); 886: 887: if ((*s_etat_processus).erreur_systeme != d_es) 888: { 889: return; 890: } 891: } 892: 893: # ifndef SEMAPHORES_NOMMES 894: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 895: { 896: (*s_etat_processus).erreur_systeme = d_es_processus; 897: return; 898: } 899: # else 900: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 901: { 902: (*s_etat_processus).erreur_systeme = d_es_processus; 903: return; 904: } 905: # endif 906: 907: sigsuspend(&masque); 908: 909: # ifndef SEMAPHORES_NOMMES 910: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 911: # else 912: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 913: # endif 914: { 915: if (errno != EINTR) 916: { 917: (*s_etat_processus).erreur_systeme = d_es_processus; 918: return; 919: } 920: } 921: 922: if ((*s_etat_processus).profilage == d_vrai) 923: { 924: profilage(s_etat_processus, NULL); 925: } 926: 927: return; 928: } 929: 930: 931: /* 932: ================================================================================ 933: Fonction 'static' 934: ================================================================================ 935: Entrées : structure processus 936: -------------------------------------------------------------------------------- 937: Sorties : 938: -------------------------------------------------------------------------------- 939: Effets de bord : néant 940: ================================================================================ 941: */ 942: 943: void 944: instruction_static(struct_processus *s_etat_processus) 945: { 946: (*s_etat_processus).erreur_execution = d_ex; 947: 948: if ((*s_etat_processus).affichage_arguments == 'Y') 949: { 950: printf("\n STATIC "); 951: 952: if ((*s_etat_processus).langue == 'F') 953: { 954: printf("(déclaration de variables statiques)\n\n"); 955: printf(" Aucun argument\n"); 956: } 957: else 958: { 959: printf("(static variables declaration)\n\n"); 960: printf(" No argument\n"); 961: } 962: 963: return; 964: } 965: else if ((*s_etat_processus).test_instruction == 'Y') 966: { 967: (*s_etat_processus).nombre_arguments = -1; 968: return; 969: } 970: 971: if (test_cfsf(s_etat_processus, 31) == d_vrai) 972: { 973: if (empilement_pile_last(s_etat_processus, 0) == d_erreur) 974: { 975: return; 976: } 977: } 978: 979: if ((*s_etat_processus).creation_variables_partagees == d_vrai) 980: { 981: (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee; 982: return; 983: } 984: 985: (*s_etat_processus).creation_variables_statiques = d_vrai; 986: 987: return; 988: } 989: 990: 991: /* 992: ================================================================================ 993: Fonction 'shared' 994: ================================================================================ 995: Entrées : structure processus 996: -------------------------------------------------------------------------------- 997: Sorties : 998: -------------------------------------------------------------------------------- 999: Effets de bord : néant 1000: ================================================================================ 1001: */ 1002: 1003: void 1004: instruction_shared(struct_processus *s_etat_processus) 1005: { 1006: (*s_etat_processus).erreur_execution = d_ex; 1007: 1008: if ((*s_etat_processus).affichage_arguments == 'Y') 1009: { 1010: printf("\n SHARED "); 1011: 1012: if ((*s_etat_processus).langue == 'F') 1013: { 1014: printf("(déclaration de variables partagées)\n\n"); 1015: printf(" Aucun argument\n"); 1016: } 1017: else 1018: { 1019: printf("(shared variables declaration)\n\n"); 1020: printf(" No argument\n"); 1021: } 1022: 1023: return; 1024: } 1025: else if ((*s_etat_processus).test_instruction == 'Y') 1026: { 1027: (*s_etat_processus).nombre_arguments = -1; 1028: return; 1029: } 1030: 1031: if (test_cfsf(s_etat_processus, 31) == d_vrai) 1032: { 1033: if (empilement_pile_last(s_etat_processus, 0) == d_erreur) 1034: { 1035: return; 1036: } 1037: } 1038: 1039: if ((*s_etat_processus).creation_variables_partagees == d_vrai) 1040: { 1041: (*s_etat_processus).erreur_execution = d_ex_variable_statique_partagee; 1042: return; 1043: } 1044: 1045: (*s_etat_processus).creation_variables_partagees = d_vrai; 1046: 1047: return; 1048: } 1049: 1050: 1051: /* 1052: ================================================================================ 1053: Fonction 'stoswi' 1054: ================================================================================ 1055: Entrées : structure processus 1056: -------------------------------------------------------------------------------- 1057: Sorties : 1058: -------------------------------------------------------------------------------- 1059: Effets de bord : néant 1060: ================================================================================ 1061: */ 1062: 1063: void 1064: instruction_stoswi(struct_processus *s_etat_processus) 1065: { 1066: integer8 interruption; 1067: 1068: struct_objet *s_objet_argument_1; 1069: struct_objet *s_objet_argument_2; 1070: 1071: (*s_etat_processus).erreur_execution = d_ex; 1072: 1073: if ((*s_etat_processus).affichage_arguments == 'Y') 1074: { 1075: printf("\n STOSWI "); 1076: 1077: if ((*s_etat_processus).langue == 'F') 1078: { 1079: printf("(définition d'une interruption logicielle)\n\n"); 1080: } 1081: else 1082: { 1083: printf("(software interrupt definition)\n\n"); 1084: } 1085: 1086: printf(" 2: %s, %s\n", d_NOM, d_RPN); 1087: printf(" 1: %s\n", d_INT); 1088: 1089: return; 1090: } 1091: else if ((*s_etat_processus).test_instruction == 'Y') 1092: { 1093: (*s_etat_processus).nombre_arguments = -1; 1094: return; 1095: } 1096: 1097: if (test_cfsf(s_etat_processus, 31) == d_vrai) 1098: { 1099: if (empilement_pile_last(s_etat_processus, 2) == d_erreur) 1100: { 1101: return; 1102: } 1103: } 1104: 1105: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 1106: &s_objet_argument_1) == d_erreur) 1107: { 1108: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 1109: return; 1110: } 1111: 1112: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 1113: &s_objet_argument_2) == d_erreur) 1114: { 1115: liberation(s_etat_processus, s_objet_argument_1); 1116: 1117: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 1118: return; 1119: } 1120: 1121: if ((*s_objet_argument_1).type == INT) 1122: { 1123: interruption = (*((integer8 *) (*s_objet_argument_1).objet)); 1124: 1125: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 1126: { 1127: liberation(s_etat_processus, s_objet_argument_1); 1128: liberation(s_etat_processus, s_objet_argument_2); 1129: 1130: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide; 1131: return; 1132: } 1133: 1134: if ((*s_objet_argument_2).type == NOM) 1135: { 1136: liberation(s_etat_processus, (*s_etat_processus).corps_interruptions 1137: [interruption - 1]); 1138: (*s_etat_processus).corps_interruptions[interruption - 1] = 1139: s_objet_argument_2; 1140: } 1141: else if((*s_objet_argument_2).type == RPN) 1142: { 1143: liberation(s_etat_processus, (*s_etat_processus).corps_interruptions 1144: [interruption - 1]); 1145: (*s_etat_processus).corps_interruptions[interruption - 1] = 1146: s_objet_argument_2; 1147: } 1148: else 1149: { 1150: liberation(s_etat_processus, s_objet_argument_1); 1151: liberation(s_etat_processus, s_objet_argument_2); 1152: 1153: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 1154: return; 1155: } 1156: } 1157: else 1158: { 1159: liberation(s_etat_processus, s_objet_argument_1); 1160: liberation(s_etat_processus, s_objet_argument_2); 1161: 1162: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 1163: return; 1164: } 1165: 1166: liberation(s_etat_processus, s_objet_argument_1); 1167: 1168: return; 1169: } 1170: 1171: 1172: /* 1173: ================================================================================ 1174: Fonction 'swi' 1175: ================================================================================ 1176: Entrées : structure processus 1177: -------------------------------------------------------------------------------- 1178: Sorties : 1179: -------------------------------------------------------------------------------- 1180: Effets de bord : néant 1181: ================================================================================ 1182: */ 1183: 1184: void 1185: instruction_swi(struct_processus *s_etat_processus) 1186: { 1187: int interruption_reduite; 1188: 1189: integer8 interruption; 1190: 1191: pid_t pid; 1192: 1193: pthread_t tid; 1194: 1195: sig_atomic_t registre; 1196: 1197: ssize_t longueur_ecriture; 1198: 1199: struct_objet *s_objet_argument; 1200: 1201: struct timespec attente; 1202: 1203: unsigned char tampon; 1204: 1205: (*s_etat_processus).erreur_execution = d_ex; 1206: 1207: if ((*s_etat_processus).affichage_arguments == 'Y') 1208: { 1209: printf("\n SWI "); 1210: 1211: if ((*s_etat_processus).langue == 'F') 1212: { 1213: printf("(interruption logicielle)\n\n"); 1214: } 1215: else 1216: { 1217: printf("(software interrupt)\n\n"); 1218: } 1219: 1220: printf(" 1: %s\n", d_INT); 1221: 1222: return; 1223: } 1224: else if ((*s_etat_processus).test_instruction == 'Y') 1225: { 1226: (*s_etat_processus).nombre_arguments = -1; 1227: return; 1228: } 1229: 1230: if (test_cfsf(s_etat_processus, 31) == d_vrai) 1231: { 1232: if (empilement_pile_last(s_etat_processus, 1) == d_erreur) 1233: { 1234: return; 1235: } 1236: } 1237: 1238: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 1239: &s_objet_argument) == d_erreur) 1240: { 1241: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 1242: return; 1243: } 1244: 1245: if ((*s_objet_argument).type == INT) 1246: { 1247: interruption = (*((integer8 *) (*s_objet_argument).objet)); 1248: 1249: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 1250: { 1251: liberation(s_etat_processus, s_objet_argument); 1252: 1253: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide; 1254: return; 1255: } 1256: 1257: if ((*s_etat_processus).presence_pipes == d_faux) 1258: { 1259: liberation(s_etat_processus, s_objet_argument); 1260: 1261: (*s_etat_processus).erreur_execution = d_ex_absence_processus_pere; 1262: return; 1263: } 1264: 1265: // Envoi d'un PID invalide (-1) pour ne pas bloquer le thread 1266: // de surveillance. 1267: 1268: registre = (*s_etat_processus).var_volatile_traitement_retarde_stop; 1269: (*s_etat_processus).var_volatile_traitement_retarde_stop = 1; 1270: 1271: if ((*s_etat_processus).processus_detache == d_vrai) 1272: { 1273: pid = -1; 1274: 1275: attente.tv_sec = 0; 1276: attente.tv_nsec = GRANULARITE_us * 1000; 1277: 1278: # ifndef SEMAPHORES_NOMMES 1279: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1280: { 1281: (*s_etat_processus).erreur_systeme = d_es_processus; 1282: return; 1283: } 1284: # else 1285: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1286: { 1287: (*s_etat_processus).erreur_systeme = d_es_processus; 1288: return; 1289: } 1290: # endif 1291: 1292: while((longueur_ecriture = write_atomic(s_etat_processus, 1293: (*s_etat_processus).pipe_nombre_objets_attente, 1294: &pid, sizeof(pid))) != sizeof(pid)) 1295: { 1296: # ifndef SEMAPHORES_NOMMES 1297: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1298: # else 1299: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1300: # endif 1301: { 1302: if (errno != EINTR) 1303: { 1304: (*s_etat_processus).erreur_systeme = d_es_processus; 1305: return; 1306: } 1307: } 1308: 1309: if (longueur_ecriture == -1) 1310: { 1311: if (registre == 0) 1312: { 1313: if ((*s_etat_processus) 1314: .var_volatile_traitement_retarde_stop == -1) 1315: { 1316: (*s_etat_processus).var_volatile_requete_arret = -1; 1317: } 1318: 1319: (*s_etat_processus) 1320: .var_volatile_traitement_retarde_stop 1321: = registre; 1322: } 1323: 1324: (*s_etat_processus).erreur_systeme = d_es_processus; 1325: return; 1326: } 1327: 1328: nanosleep(&attente, NULL); 1329: INCR_GRANULARITE(attente.tv_nsec); 1330: 1331: # ifndef SEMAPHORES_NOMMES 1332: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1333: # else 1334: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1335: # endif 1336: { 1337: (*s_etat_processus).erreur_systeme = d_es_processus; 1338: return; 1339: } 1340: } 1341: 1342: # ifndef SEMAPHORES_NOMMES 1343: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1344: # else 1345: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1346: # endif 1347: { 1348: if (errno != EINTR) 1349: { 1350: (*s_etat_processus).erreur_systeme = d_es_processus; 1351: return; 1352: } 1353: } 1354: } 1355: else 1356: { 1357: tid = -1; 1358: 1359: attente.tv_sec = 0; 1360: attente.tv_nsec = GRANULARITE_us * 1000; 1361: 1362: # ifndef SEMAPHORES_NOMMES 1363: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1364: { 1365: (*s_etat_processus).erreur_systeme = d_es_processus; 1366: return; 1367: } 1368: # else 1369: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1370: { 1371: (*s_etat_processus).erreur_systeme = d_es_processus; 1372: return; 1373: } 1374: # endif 1375: 1376: while((longueur_ecriture = write_atomic(s_etat_processus, 1377: (*s_etat_processus).pipe_nombre_objets_attente, 1378: &tid, sizeof(tid))) != sizeof(tid)) 1379: { 1380: # ifndef SEMAPHORES_NOMMES 1381: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1382: # else 1383: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1384: # endif 1385: { 1386: if (errno != EINTR) 1387: { 1388: (*s_etat_processus).erreur_systeme = d_es_processus; 1389: return; 1390: } 1391: } 1392: 1393: if (longueur_ecriture == -1) 1394: { 1395: if (registre == 0) 1396: { 1397: if ((*s_etat_processus) 1398: .var_volatile_traitement_retarde_stop == -1) 1399: { 1400: (*s_etat_processus).var_volatile_requete_arret = -1; 1401: } 1402: 1403: (*s_etat_processus) 1404: .var_volatile_traitement_retarde_stop 1405: = registre; 1406: } 1407: 1408: (*s_etat_processus).erreur_systeme = d_es_processus; 1409: return; 1410: } 1411: 1412: nanosleep(&attente, NULL); 1413: INCR_GRANULARITE(attente.tv_nsec); 1414: 1415: # ifndef SEMAPHORES_NOMMES 1416: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1417: { 1418: (*s_etat_processus).erreur_systeme = d_es_processus; 1419: return; 1420: } 1421: # else 1422: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1423: { 1424: (*s_etat_processus).erreur_systeme = d_es_processus; 1425: return; 1426: } 1427: # endif 1428: } 1429: 1430: # ifndef SEMAPHORES_NOMMES 1431: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1432: # else 1433: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1434: # endif 1435: { 1436: if (errno != EINTR) 1437: { 1438: (*s_etat_processus).erreur_systeme = d_es_processus; 1439: return; 1440: } 1441: } 1442: } 1443: 1444: interruption_reduite = interruption; 1445: 1446: attente.tv_sec = 0; 1447: attente.tv_nsec = GRANULARITE_us * 1000; 1448: 1449: # ifndef SEMAPHORES_NOMMES 1450: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1451: { 1452: (*s_etat_processus).erreur_systeme = d_es_processus; 1453: return; 1454: } 1455: # else 1456: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1457: { 1458: (*s_etat_processus).erreur_systeme = d_es_processus; 1459: return; 1460: } 1461: # endif 1462: 1463: while((longueur_ecriture = write_atomic(s_etat_processus, 1464: (*s_etat_processus).pipe_interruptions, 1465: &interruption_reduite, sizeof(interruption_reduite))) 1466: != sizeof(interruption_reduite)) 1467: { 1468: # ifndef SEMAPHORES_NOMMES 1469: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1470: # else 1471: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1472: # endif 1473: { 1474: if (errno != EINTR) 1475: { 1476: (*s_etat_processus).erreur_systeme = d_es_processus; 1477: return; 1478: } 1479: } 1480: 1481: if (longueur_ecriture == -1) 1482: { 1483: if (registre == 0) 1484: { 1485: if ((*s_etat_processus) 1486: .var_volatile_traitement_retarde_stop == -1) 1487: { 1488: (*s_etat_processus).var_volatile_requete_arret = -1; 1489: } 1490: 1491: (*s_etat_processus) 1492: .var_volatile_traitement_retarde_stop 1493: = registre; 1494: } 1495: 1496: (*s_etat_processus).erreur_systeme = d_es_processus; 1497: return; 1498: } 1499: 1500: nanosleep(&attente, NULL); 1501: INCR_GRANULARITE(attente.tv_nsec); 1502: 1503: # ifndef SEMAPHORES_NOMMES 1504: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1505: { 1506: (*s_etat_processus).erreur_systeme = d_es_processus; 1507: return; 1508: } 1509: # else 1510: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1511: { 1512: (*s_etat_processus).erreur_systeme = d_es_processus; 1513: return; 1514: } 1515: # endif 1516: } 1517: 1518: # ifndef SEMAPHORES_NOMMES 1519: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1520: # else 1521: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1522: # endif 1523: { 1524: if (errno != EINTR) 1525: { 1526: (*s_etat_processus).erreur_systeme = d_es_processus; 1527: return; 1528: } 1529: } 1530: 1531: if ((*s_etat_processus).processus_detache == d_vrai) 1532: { 1533: pid = -3; 1534: 1535: attente.tv_sec = 0; 1536: attente.tv_nsec = GRANULARITE_us * 1000; 1537: 1538: # ifndef SEMAPHORES_NOMMES 1539: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1540: { 1541: (*s_etat_processus).erreur_systeme = d_es_processus; 1542: return; 1543: } 1544: # else 1545: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1546: { 1547: (*s_etat_processus).erreur_systeme = d_es_processus; 1548: return; 1549: } 1550: # endif 1551: 1552: while((longueur_ecriture = write_atomic(s_etat_processus, 1553: (*s_etat_processus).pipe_nombre_interruptions_attente, 1554: &pid, sizeof(pid))) != sizeof(pid)) 1555: { 1556: # ifndef SEMAPHORES_NOMMES 1557: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1558: # else 1559: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1560: # endif 1561: { 1562: (*s_etat_processus).erreur_systeme = d_es_processus; 1563: return; 1564: } 1565: 1566: if (longueur_ecriture == -1) 1567: { 1568: if (registre == 0) 1569: { 1570: if ((*s_etat_processus) 1571: .var_volatile_traitement_retarde_stop == -1) 1572: { 1573: (*s_etat_processus).var_volatile_requete_arret = -1; 1574: } 1575: 1576: (*s_etat_processus) 1577: .var_volatile_traitement_retarde_stop 1578: = registre; 1579: } 1580: 1581: (*s_etat_processus).erreur_systeme = d_es_processus; 1582: return; 1583: } 1584: 1585: nanosleep(&attente, NULL); 1586: INCR_GRANULARITE(attente.tv_nsec); 1587: 1588: # ifndef SEMAPHORES_NOMMES 1589: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1590: { 1591: (*s_etat_processus).erreur_systeme = d_es_processus; 1592: return; 1593: } 1594: # else 1595: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1596: { 1597: (*s_etat_processus).erreur_systeme = d_es_processus; 1598: return; 1599: } 1600: # endif 1601: } 1602: 1603: pid = getpid(); 1604: 1605: attente.tv_sec = 0; 1606: attente.tv_nsec = GRANULARITE_us * 1000; 1607: 1608: while((longueur_ecriture = write_atomic(s_etat_processus, 1609: (*s_etat_processus).pipe_nombre_interruptions_attente, 1610: &pid, sizeof(pid))) != sizeof(pid)) 1611: { 1612: # ifndef SEMAPHORES_NOMMES 1613: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1614: # else 1615: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1616: # endif 1617: { 1618: if (errno != EINTR) 1619: { 1620: (*s_etat_processus).erreur_systeme = d_es_processus; 1621: return; 1622: } 1623: } 1624: 1625: if (longueur_ecriture == -1) 1626: { 1627: if (registre == 0) 1628: { 1629: if ((*s_etat_processus) 1630: .var_volatile_traitement_retarde_stop == -1) 1631: { 1632: (*s_etat_processus).var_volatile_requete_arret = -1; 1633: } 1634: 1635: (*s_etat_processus) 1636: .var_volatile_traitement_retarde_stop 1637: = registre; 1638: } 1639: 1640: (*s_etat_processus).erreur_systeme = d_es_processus; 1641: return; 1642: } 1643: 1644: nanosleep(&attente, NULL); 1645: INCR_GRANULARITE(attente.tv_nsec); 1646: 1647: # ifndef SEMAPHORES_NOMMES 1648: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1649: { 1650: (*s_etat_processus).erreur_systeme = d_es_processus; 1651: return; 1652: } 1653: # else 1654: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1655: { 1656: (*s_etat_processus).erreur_systeme = d_es_processus; 1657: return; 1658: } 1659: # endif 1660: } 1661: 1662: # ifndef SEMAPHORES_NOMMES 1663: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1664: # else 1665: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1666: # endif 1667: { 1668: if (errno != EINTR) 1669: { 1670: (*s_etat_processus).erreur_systeme = d_es_processus; 1671: return; 1672: } 1673: } 1674: } 1675: else 1676: { 1677: tid = -3; 1678: 1679: # ifndef SEMAPHORES_NOMMES 1680: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1681: { 1682: (*s_etat_processus).erreur_systeme = d_es_processus; 1683: return; 1684: } 1685: # else 1686: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1687: { 1688: (*s_etat_processus).erreur_systeme = d_es_processus; 1689: return; 1690: } 1691: # endif 1692: 1693: while((longueur_ecriture = write_atomic(s_etat_processus, 1694: (*s_etat_processus).pipe_nombre_interruptions_attente, 1695: &tid, sizeof(tid))) != sizeof(tid)) 1696: { 1697: # ifndef SEMAPHORES_NOMMES 1698: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1699: # else 1700: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1701: # endif 1702: { 1703: if (errno != EINTR) 1704: { 1705: (*s_etat_processus).erreur_systeme = d_es_processus; 1706: return; 1707: } 1708: } 1709: 1710: if (longueur_ecriture == -1) 1711: { 1712: if (registre == 0) 1713: { 1714: if ((*s_etat_processus) 1715: .var_volatile_traitement_retarde_stop == -1) 1716: { 1717: (*s_etat_processus).var_volatile_requete_arret = -1; 1718: } 1719: 1720: (*s_etat_processus) 1721: .var_volatile_traitement_retarde_stop 1722: = registre; 1723: } 1724: 1725: (*s_etat_processus).erreur_systeme = d_es_processus; 1726: return; 1727: } 1728: 1729: nanosleep(&attente, NULL); 1730: INCR_GRANULARITE(attente.tv_nsec); 1731: 1732: # ifndef SEMAPHORES_NOMMES 1733: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1734: { 1735: (*s_etat_processus).erreur_systeme = d_es_processus; 1736: return; 1737: } 1738: # else 1739: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1740: { 1741: (*s_etat_processus).erreur_systeme = d_es_processus; 1742: return; 1743: } 1744: # endif 1745: } 1746: 1747: tid = pthread_self(); 1748: 1749: attente.tv_sec = 0; 1750: attente.tv_nsec = GRANULARITE_us * 1000; 1751: 1752: while((longueur_ecriture = write_atomic(s_etat_processus, 1753: (*s_etat_processus).pipe_nombre_interruptions_attente, 1754: &tid, sizeof(tid))) != sizeof(tid)) 1755: { 1756: # ifndef SEMAPHORES_NOMMES 1757: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1758: # else 1759: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1760: # endif 1761: { 1762: if (errno != EINTR) 1763: { 1764: (*s_etat_processus).erreur_systeme = d_es_processus; 1765: return; 1766: } 1767: } 1768: 1769: if (longueur_ecriture == -1) 1770: 1771: { 1772: if (registre == 0) 1773: { 1774: if ((*s_etat_processus) 1775: .var_volatile_traitement_retarde_stop == -1) 1776: { 1777: (*s_etat_processus).var_volatile_requete_arret = -1; 1778: } 1779: 1780: (*s_etat_processus) 1781: .var_volatile_traitement_retarde_stop 1782: = registre; 1783: } 1784: 1785: (*s_etat_processus).erreur_systeme = d_es_processus; 1786: return; 1787: } 1788: 1789: nanosleep(&attente, NULL); 1790: INCR_GRANULARITE(attente.tv_nsec); 1791: 1792: # ifndef SEMAPHORES_NOMMES 1793: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1794: { 1795: (*s_etat_processus).erreur_systeme = d_es_processus; 1796: return; 1797: } 1798: # else 1799: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1800: { 1801: (*s_etat_processus).erreur_systeme = d_es_processus; 1802: return; 1803: } 1804: # endif 1805: } 1806: 1807: # ifndef SEMAPHORES_NOMMES 1808: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1809: # else 1810: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1811: # endif 1812: { 1813: if (errno != EINTR) 1814: { 1815: (*s_etat_processus).erreur_systeme = d_es_processus; 1816: return; 1817: } 1818: } 1819: } 1820: 1821: attente.tv_sec = 0; 1822: attente.tv_nsec = GRANULARITE_us * 1000; 1823: 1824: # ifndef SEMAPHORES_NOMMES 1825: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1826: { 1827: (*s_etat_processus).erreur_systeme = d_es_processus; 1828: return; 1829: } 1830: # else 1831: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1832: { 1833: (*s_etat_processus).erreur_systeme = d_es_processus; 1834: return; 1835: } 1836: # endif 1837: 1838: while(read_atomic(s_etat_processus, 1839: (*s_etat_processus).pipe_acquittement, 1840: &tampon, sizeof(unsigned char)) != sizeof(unsigned char)) 1841: { 1842: # ifndef SEMAPHORES_NOMMES 1843: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1844: # else 1845: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1846: # endif 1847: { 1848: if (errno != EINTR) 1849: { 1850: (*s_etat_processus).erreur_systeme = d_es_processus; 1851: return; 1852: } 1853: } 1854: 1855: nanosleep(&attente, NULL); 1856: INCR_GRANULARITE(attente.tv_nsec); 1857: 1858: # ifndef SEMAPHORES_NOMMES 1859: if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) 1860: # else 1861: if (sem_post((*s_etat_processus).semaphore_fork) != 0) 1862: # endif 1863: { 1864: (*s_etat_processus).erreur_systeme = d_es_processus; 1865: return; 1866: } 1867: } 1868: 1869: # ifndef SEMAPHORES_NOMMES 1870: while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) 1871: # else 1872: while(sem_wait((*s_etat_processus).semaphore_fork) == -1) 1873: # endif 1874: { 1875: if (errno != EINTR) 1876: { 1877: (*s_etat_processus).erreur_systeme = d_es_processus; 1878: return; 1879: } 1880: } 1881: 1882: if (registre == 0) 1883: { 1884: if ((*s_etat_processus).var_volatile_traitement_retarde_stop == -1) 1885: { 1886: (*s_etat_processus).var_volatile_requete_arret = -1; 1887: } 1888: 1889: (*s_etat_processus).var_volatile_traitement_retarde_stop = registre; 1890: } 1891: } 1892: else 1893: { 1894: liberation(s_etat_processus, s_objet_argument); 1895: 1896: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 1897: return; 1898: } 1899: 1900: liberation(s_etat_processus, s_objet_argument); 1901: 1902: return; 1903: } 1904: 1905: 1906: /* 1907: ================================================================================ 1908: Fonction 'swilock' 1909: ================================================================================ 1910: Entrées : structure processus 1911: -------------------------------------------------------------------------------- 1912: Sorties : 1913: -------------------------------------------------------------------------------- 1914: Effets de bord : néant 1915: ================================================================================ 1916: */ 1917: 1918: void 1919: instruction_swilock(struct_processus *s_etat_processus) 1920: { 1921: integer8 interruption; 1922: 1923: struct_liste_chainee *l_element_courant; 1924: 1925: struct_objet *s_objet_argument; 1926: 1927: (*s_etat_processus).erreur_execution = d_ex; 1928: 1929: if ((*s_etat_processus).affichage_arguments == 'Y') 1930: { 1931: printf("\n SWILOCK "); 1932: 1933: if ((*s_etat_processus).langue == 'F') 1934: { 1935: printf("(verrouillage des interruptions logicielles)\n\n"); 1936: } 1937: else 1938: { 1939: printf("(software interrupt lock)\n\n"); 1940: } 1941: 1942: printf(" 1: %s, %s\n", d_INT, d_LST); 1943: 1944: return; 1945: } 1946: else if ((*s_etat_processus).test_instruction == 'Y') 1947: { 1948: (*s_etat_processus).nombre_arguments = -1; 1949: return; 1950: } 1951: 1952: if (test_cfsf(s_etat_processus, 31) == d_vrai) 1953: { 1954: if (empilement_pile_last(s_etat_processus, 1) == d_erreur) 1955: { 1956: return; 1957: } 1958: } 1959: 1960: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 1961: &s_objet_argument) == d_erreur) 1962: { 1963: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 1964: return; 1965: } 1966: 1967: if ((*s_objet_argument).type == INT) 1968: { 1969: interruption = (*((integer8 *) (*s_objet_argument).objet)); 1970: 1971: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 1972: { 1973: liberation(s_etat_processus, s_objet_argument); 1974: 1975: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide; 1976: return; 1977: } 1978: 1979: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I'; 1980: } 1981: else if ((*s_objet_argument).type == LST) 1982: { 1983: l_element_courant = (*s_objet_argument).objet; 1984: 1985: while(l_element_courant) 1986: { 1987: if ((*(*l_element_courant).donnee).type != INT) 1988: { 1989: liberation(s_etat_processus, s_objet_argument); 1990: 1991: (*s_etat_processus).erreur_execution = 1992: d_ex_erreur_type_argument; 1993: return; 1994: } 1995: 1996: interruption = (*((integer8 *) (*(*l_element_courant) 1997: .donnee).objet)); 1998: 1999: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 2000: { 2001: liberation(s_etat_processus, s_objet_argument); 2002: 2003: (*s_etat_processus).erreur_execution = 2004: d_ex_interruption_invalide; 2005: return; 2006: } 2007: 2008: (*s_etat_processus).masque_interruptions[interruption - 1] = 'I'; 2009: l_element_courant = (*l_element_courant).suivant; 2010: } 2011: } 2012: else 2013: { 2014: liberation(s_etat_processus, s_objet_argument); 2015: 2016: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 2017: return; 2018: } 2019: 2020: liberation(s_etat_processus, s_objet_argument); 2021: 2022: return; 2023: } 2024: 2025: 2026: /* 2027: ================================================================================ 2028: Fonction 'swistatus' 2029: ================================================================================ 2030: Entrées : structure processus 2031: -------------------------------------------------------------------------------- 2032: Sorties : 2033: -------------------------------------------------------------------------------- 2034: Effets de bord : néant 2035: ================================================================================ 2036: */ 2037: 2038: void 2039: instruction_swistatus(struct_processus *s_etat_processus) 2040: { 2041: int i; 2042: 2043: struct_liste_chainee *l_element_courant; 2044: struct_liste_chainee *l_element_futur; 2045: struct_liste_chainee *l_element_liste; 2046: 2047: struct_objet *s_objet_resultat; 2048: 2049: (*s_etat_processus).erreur_execution = d_ex; 2050: 2051: if ((*s_etat_processus).affichage_arguments == 'Y') 2052: { 2053: printf("\n SWISTATUS "); 2054: 2055: if ((*s_etat_processus).langue == 'F') 2056: { 2057: printf("(état des interruptions logicielles)\n\n"); 2058: } 2059: else 2060: { 2061: printf("(software interrupts status)\n\n"); 2062: } 2063: 2064: printf("-> 1: %s\n\n", d_LST); 2065: 2066: if ((*s_etat_processus).langue == 'F') 2067: { 2068: printf(" Utilisation :\n\n"); 2069: } 2070: else 2071: { 2072: printf(" Usage:\n\n"); 2073: } 2074: 2075: printf(" { { initialized interrupts }\n" 2076: " { unlocked interrupts }\n" 2077: " { queued interrupts }\n" 2078: " { locked interrupts } }\n"); 2079: return; 2080: } 2081: else if ((*s_etat_processus).test_instruction == 'Y') 2082: { 2083: (*s_etat_processus).nombre_arguments = -1; 2084: return; 2085: } 2086: 2087: if (test_cfsf(s_etat_processus, 31) == d_vrai) 2088: { 2089: if (empilement_pile_last(s_etat_processus, 0) == d_erreur) 2090: { 2091: return; 2092: } 2093: } 2094: 2095: if ((s_objet_resultat = allocation(s_etat_processus, LST)) == NULL) 2096: { 2097: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2098: return; 2099: } 2100: 2101: if (((*s_objet_resultat).objet = 2102: allocation_maillon(s_etat_processus)) == NULL) 2103: { 2104: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2105: return; 2106: } 2107: 2108: l_element_courant = (struct_liste_chainee *) (*s_objet_resultat).objet; 2109: 2110: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST)) 2111: == NULL) 2112: { 2113: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2114: return; 2115: } 2116: 2117: l_element_liste = NULL; 2118: l_element_futur = NULL; 2119: 2120: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) 2121: { 2122: if ((*s_etat_processus).corps_interruptions[i] != NULL) 2123: { 2124: if (l_element_liste == NULL) 2125: { 2126: if ((l_element_liste = 2127: allocation_maillon(s_etat_processus)) == NULL) 2128: { 2129: (*s_etat_processus).erreur_systeme = 2130: d_es_allocation_memoire; 2131: return; 2132: } 2133: 2134: l_element_futur = l_element_liste; 2135: } 2136: else 2137: { 2138: if (((*l_element_liste).suivant = 2139: allocation_maillon(s_etat_processus)) == NULL) 2140: { 2141: (*s_etat_processus).erreur_systeme = 2142: d_es_allocation_memoire; 2143: return; 2144: } 2145: 2146: l_element_liste = (*l_element_liste).suivant; 2147: } 2148: 2149: (*l_element_liste).suivant = NULL; 2150: 2151: if (((*l_element_liste).donnee = allocation(s_etat_processus, 2152: INT)) == NULL) 2153: { 2154: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2155: return; 2156: } 2157: 2158: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1; 2159: } 2160: } 2161: 2162: (*(*l_element_courant).donnee).objet = l_element_futur; 2163: 2164: if (((*l_element_courant).suivant = 2165: allocation_maillon(s_etat_processus)) == NULL) 2166: { 2167: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2168: return; 2169: } 2170: 2171: l_element_courant = (*l_element_courant).suivant; 2172: 2173: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST)) 2174: == NULL) 2175: { 2176: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2177: return; 2178: } 2179: 2180: l_element_liste = NULL; 2181: l_element_futur = NULL; 2182: 2183: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) 2184: { 2185: if ((*s_etat_processus).masque_interruptions[i] == 'N') 2186: { 2187: if (l_element_liste == NULL) 2188: { 2189: if ((l_element_liste = 2190: allocation_maillon(s_etat_processus)) == NULL) 2191: { 2192: (*s_etat_processus).erreur_systeme = 2193: d_es_allocation_memoire; 2194: return; 2195: } 2196: 2197: l_element_futur = l_element_liste; 2198: } 2199: else 2200: { 2201: if (((*l_element_liste).suivant = 2202: allocation_maillon(s_etat_processus)) == NULL) 2203: { 2204: (*s_etat_processus).erreur_systeme = 2205: d_es_allocation_memoire; 2206: return; 2207: } 2208: 2209: l_element_liste = (*l_element_liste).suivant; 2210: } 2211: 2212: (*l_element_liste).suivant = NULL; 2213: 2214: if (((*l_element_liste).donnee = allocation(s_etat_processus, 2215: INT)) == NULL) 2216: { 2217: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2218: return; 2219: } 2220: 2221: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1; 2222: } 2223: } 2224: 2225: (*(*l_element_courant).donnee).objet = l_element_futur; 2226: 2227: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus)) 2228: == NULL) 2229: { 2230: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2231: return; 2232: } 2233: 2234: l_element_courant = (*l_element_courant).suivant; 2235: 2236: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST)) 2237: == NULL) 2238: { 2239: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2240: return; 2241: } 2242: 2243: l_element_liste = NULL; 2244: l_element_futur = NULL; 2245: 2246: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) 2247: { 2248: if ((*s_etat_processus).masque_interruptions[i] == 'Q') 2249: { 2250: if (l_element_liste == NULL) 2251: { 2252: if ((l_element_liste = 2253: allocation_maillon(s_etat_processus)) == NULL) 2254: { 2255: (*s_etat_processus).erreur_systeme = 2256: d_es_allocation_memoire; 2257: return; 2258: } 2259: 2260: l_element_futur = l_element_liste; 2261: } 2262: else 2263: { 2264: if (((*l_element_liste).suivant = 2265: allocation_maillon(s_etat_processus)) == NULL) 2266: { 2267: (*s_etat_processus).erreur_systeme = 2268: d_es_allocation_memoire; 2269: return; 2270: } 2271: 2272: l_element_liste = (*l_element_liste).suivant; 2273: } 2274: 2275: (*l_element_liste).suivant = NULL; 2276: 2277: if (((*l_element_liste).donnee = allocation(s_etat_processus, 2278: INT)) == NULL) 2279: { 2280: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2281: return; 2282: } 2283: 2284: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1; 2285: } 2286: } 2287: 2288: (*(*l_element_courant).donnee).objet = l_element_futur; 2289: 2290: if (((*l_element_courant).suivant = allocation_maillon(s_etat_processus)) 2291: == NULL) 2292: { 2293: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2294: return; 2295: } 2296: 2297: l_element_courant = (*l_element_courant).suivant; 2298: 2299: if (((*l_element_courant).donnee = allocation(s_etat_processus, LST)) 2300: == NULL) 2301: { 2302: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2303: return; 2304: } 2305: 2306: l_element_liste = NULL; 2307: l_element_futur = NULL; 2308: 2309: for(i = 0; i < d_NOMBRE_INTERRUPTIONS; i++) 2310: { 2311: if ((*s_etat_processus).masque_interruptions[i] == 'I') 2312: { 2313: if (l_element_liste == NULL) 2314: { 2315: if ((l_element_liste = 2316: allocation_maillon(s_etat_processus)) == NULL) 2317: { 2318: (*s_etat_processus).erreur_systeme = 2319: d_es_allocation_memoire; 2320: return; 2321: } 2322: 2323: l_element_futur = l_element_liste; 2324: } 2325: else 2326: { 2327: if (((*l_element_liste).suivant = 2328: allocation_maillon(s_etat_processus)) == NULL) 2329: { 2330: (*s_etat_processus).erreur_systeme = 2331: d_es_allocation_memoire; 2332: return; 2333: } 2334: 2335: l_element_liste = (*l_element_liste).suivant; 2336: } 2337: 2338: (*l_element_liste).suivant = NULL; 2339: 2340: if (((*l_element_liste).donnee = allocation(s_etat_processus, 2341: INT)) == NULL) 2342: { 2343: (*s_etat_processus).erreur_systeme = d_es_allocation_memoire; 2344: return; 2345: } 2346: 2347: (*((integer8 *) (*(*l_element_liste).donnee).objet)) = i + 1; 2348: } 2349: } 2350: 2351: (*(*l_element_courant).donnee).objet = l_element_futur; 2352: 2353: (*l_element_courant).suivant = NULL; 2354: 2355: if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 2356: s_objet_resultat) == d_erreur) 2357: { 2358: return; 2359: } 2360: 2361: return; 2362: } 2363: 2364: 2365: /* 2366: ================================================================================ 2367: Fonction 'swiunlock' 2368: ================================================================================ 2369: Entrées : structure processus 2370: -------------------------------------------------------------------------------- 2371: Sorties : 2372: -------------------------------------------------------------------------------- 2373: Effets de bord : néant 2374: ================================================================================ 2375: */ 2376: 2377: void 2378: instruction_swiunlock(struct_processus *s_etat_processus) 2379: { 2380: integer8 interruption; 2381: 2382: struct_liste_chainee *l_element_courant; 2383: 2384: struct_objet *s_objet_argument; 2385: 2386: (*s_etat_processus).erreur_execution = d_ex; 2387: 2388: if ((*s_etat_processus).affichage_arguments == 'Y') 2389: { 2390: printf("\n SWIUNLOCK "); 2391: 2392: if ((*s_etat_processus).langue == 'F') 2393: { 2394: printf("(déverrouillage des interruptions logicielles)\n\n"); 2395: } 2396: else 2397: { 2398: printf("(software interrupt unlock)\n\n"); 2399: } 2400: 2401: printf(" 1: %s, %s\n", d_INT, d_LST); 2402: 2403: return; 2404: } 2405: else if ((*s_etat_processus).test_instruction == 'Y') 2406: { 2407: (*s_etat_processus).nombre_arguments = -1; 2408: return; 2409: } 2410: 2411: if (test_cfsf(s_etat_processus, 31) == d_vrai) 2412: { 2413: if (empilement_pile_last(s_etat_processus, 1) == d_erreur) 2414: { 2415: return; 2416: } 2417: } 2418: 2419: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 2420: &s_objet_argument) == d_erreur) 2421: { 2422: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 2423: return; 2424: } 2425: 2426: if ((*s_objet_argument).type == INT) 2427: { 2428: interruption = (*((integer8 *) (*s_objet_argument).objet)); 2429: 2430: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 2431: { 2432: liberation(s_etat_processus, s_objet_argument); 2433: 2434: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide; 2435: return; 2436: } 2437: 2438: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N'; 2439: } 2440: else if ((*s_objet_argument).type == LST) 2441: { 2442: l_element_courant = (*s_objet_argument).objet; 2443: 2444: while(l_element_courant) 2445: { 2446: if ((*(*l_element_courant).donnee).type != INT) 2447: { 2448: liberation(s_etat_processus, s_objet_argument); 2449: 2450: (*s_etat_processus).erreur_execution = 2451: d_ex_erreur_type_argument; 2452: return; 2453: } 2454: 2455: interruption = (*((integer8 *) (*(*l_element_courant) 2456: .donnee).objet)); 2457: 2458: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 2459: { 2460: liberation(s_etat_processus, s_objet_argument); 2461: 2462: (*s_etat_processus).erreur_execution = 2463: d_ex_interruption_invalide; 2464: return; 2465: } 2466: 2467: (*s_etat_processus).masque_interruptions[interruption - 1] = 'N'; 2468: l_element_courant = (*l_element_courant).suivant; 2469: } 2470: } 2471: else 2472: { 2473: liberation(s_etat_processus, s_objet_argument); 2474: 2475: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 2476: return; 2477: } 2478: 2479: liberation(s_etat_processus, s_objet_argument); 2480: 2481: return; 2482: } 2483: 2484: 2485: /* 2486: ================================================================================ 2487: Fonction 'swiqueue' 2488: ================================================================================ 2489: Entrées : structure processus 2490: -------------------------------------------------------------------------------- 2491: Sorties : 2492: -------------------------------------------------------------------------------- 2493: Effets de bord : néant 2494: ================================================================================ 2495: */ 2496: 2497: void 2498: instruction_swiqueue(struct_processus *s_etat_processus) 2499: { 2500: integer8 interruption; 2501: 2502: struct_liste_chainee *l_element_courant; 2503: 2504: struct_objet *s_objet_argument; 2505: 2506: (*s_etat_processus).erreur_execution = d_ex; 2507: 2508: if ((*s_etat_processus).affichage_arguments == 'Y') 2509: { 2510: printf("\n SWIQUEUE "); 2511: 2512: if ((*s_etat_processus).langue == 'F') 2513: { 2514: printf("(enregistre des interruptions logicielles)\n\n"); 2515: } 2516: else 2517: { 2518: printf("(software interrupt record)\n\n"); 2519: } 2520: 2521: printf(" 1: %s, %s\n", d_INT, d_LST); 2522: 2523: return; 2524: } 2525: else if ((*s_etat_processus).test_instruction == 'Y') 2526: { 2527: (*s_etat_processus).nombre_arguments = -1; 2528: return; 2529: } 2530: 2531: if (test_cfsf(s_etat_processus, 31) == d_vrai) 2532: { 2533: if (empilement_pile_last(s_etat_processus, 1) == d_erreur) 2534: { 2535: return; 2536: } 2537: } 2538: 2539: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 2540: &s_objet_argument) == d_erreur) 2541: { 2542: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 2543: return; 2544: } 2545: 2546: if ((*s_objet_argument).type == INT) 2547: { 2548: interruption = (*((integer8 *) (*s_objet_argument).objet)); 2549: 2550: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 2551: { 2552: liberation(s_etat_processus, s_objet_argument); 2553: 2554: (*s_etat_processus).erreur_execution = d_ex_interruption_invalide; 2555: return; 2556: } 2557: 2558: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q'; 2559: } 2560: else if ((*s_objet_argument).type == LST) 2561: { 2562: l_element_courant = (*s_objet_argument).objet; 2563: 2564: while(l_element_courant) 2565: { 2566: if ((*(*l_element_courant).donnee).type != INT) 2567: { 2568: liberation(s_etat_processus, s_objet_argument); 2569: 2570: (*s_etat_processus).erreur_execution = 2571: d_ex_erreur_type_argument; 2572: return; 2573: } 2574: 2575: interruption = (*((integer8 *) (*(*l_element_courant) 2576: .donnee).objet)); 2577: 2578: if ((interruption < 1) || (interruption > d_NOMBRE_INTERRUPTIONS)) 2579: { 2580: liberation(s_etat_processus, s_objet_argument); 2581: 2582: (*s_etat_processus).erreur_execution = 2583: d_ex_interruption_invalide; 2584: return; 2585: } 2586: 2587: (*s_etat_processus).masque_interruptions[interruption - 1] = 'Q'; 2588: l_element_courant = (*l_element_courant).suivant; 2589: } 2590: } 2591: else 2592: { 2593: liberation(s_etat_processus, s_objet_argument); 2594: 2595: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 2596: return; 2597: } 2598: 2599: liberation(s_etat_processus, s_objet_argument); 2600: 2601: return; 2602: } 2603: 2604: 2605: /* 2606: ================================================================================ 2607: Fonction 'sched' 2608: ================================================================================ 2609: Entrées : structure processus 2610: -------------------------------------------------------------------------------- 2611: Sorties : 2612: -------------------------------------------------------------------------------- 2613: Effets de bord : néant 2614: ================================================================================ 2615: */ 2616: 2617: void 2618: instruction_sched(struct_processus *s_etat_processus) 2619: { 2620: real8 pourcentage; 2621: 2622: struct_objet *s_objet_argument; 2623: 2624: (*s_etat_processus).erreur_execution = d_ex; 2625: 2626: if ((*s_etat_processus).affichage_arguments == 'Y') 2627: { 2628: printf("\n SCHED "); 2629: 2630: if ((*s_etat_processus).langue == 'F') 2631: { 2632: printf("(limitation des ressources de calcul)\n\n"); 2633: } 2634: else 2635: { 2636: printf("(CPU ressources limitation)\n\n"); 2637: } 2638: 2639: printf(" 1: %s, %s\n", d_INT, d_REL); 2640: 2641: return; 2642: } 2643: else if ((*s_etat_processus).test_instruction == 'Y') 2644: { 2645: (*s_etat_processus).nombre_arguments = -1; 2646: return; 2647: } 2648: 2649: if (test_cfsf(s_etat_processus, 31) == d_vrai) 2650: { 2651: if (empilement_pile_last(s_etat_processus, 1) == d_erreur) 2652: { 2653: return; 2654: } 2655: } 2656: 2657: if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile), 2658: &s_objet_argument) == d_erreur) 2659: { 2660: (*s_etat_processus).erreur_execution = d_ex_manque_argument; 2661: return; 2662: } 2663: 2664: if ((*s_objet_argument).type == INT) 2665: { 2666: pourcentage = (real8) (*((integer8 *) (*s_objet_argument).objet)); 2667: } 2668: else if ((*s_objet_argument).type == REL) 2669: { 2670: pourcentage = (*((real8 *) (*s_objet_argument).objet)); 2671: } 2672: else 2673: { 2674: liberation(s_etat_processus, s_objet_argument); 2675: 2676: (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument; 2677: return; 2678: } 2679: 2680: liberation(s_etat_processus, s_objet_argument); 2681: 2682: if ((pourcentage <= 0) || (pourcentage > 100)) 2683: { 2684: (*s_etat_processus).erreur_execution = d_ex_argument_invalide; 2685: return; 2686: } 2687: 2688: (*s_etat_processus).pourcentage_maximal_cpu = pourcentage; 2689: 2690: return; 2691: } 2692: 2693: // vim: ts=4