File:  [local] / rpl / src / operations_atomiques.c
Revision 1.23: download - view: text, annotated - select for diffs - revision graph
Tue Jun 21 15:26:35 2011 UTC (12 years, 10 months ago) by bertrand
Branches: MAIN
CVS tags: HEAD
Correction d'une réinitialisation sauvage de la pile des variables par niveau
dans la copie de la structure de description du processus. Cela corrige
la fonction SPAWN qui échouait sur un segmentation fault car la pile des
variables par niveau était vide alors même que l'arbre des variables contenait
bien les variables. Passage à la prerelease 2.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.0.prerelease.2
    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:   Procédure de lecture atomique
   29: ================================================================================
   30:   Entrée :
   31: --------------------------------------------------------------------------------
   32:   Sortie :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: ssize_t
   39: read_atomic(struct_processus *s_etat_processus,
   40:         int descripteur, void *tampon, size_t longueur_tampon)
   41: {
   42:     logical1            drapeau;
   43: 
   44:     size_t              longueur_residuelle;
   45:     ssize_t             longueur_lue;
   46: 
   47:     struct timespec     attente;
   48: 
   49:     void                *pointeur;
   50: 
   51:     longueur_residuelle = longueur_tampon;
   52:     pointeur = tampon;
   53: 
   54:     attente.tv_sec = 0;
   55:     attente.tv_nsec = GRANULARITE_us * 1000;
   56: 
   57:     while(longueur_residuelle != 0)
   58:     {
   59:         errno = 0;
   60:         longueur_lue = 0;
   61: 
   62:         while(longueur_lue == 0)
   63:         {
   64:             do
   65:             {
   66:                 longueur_lue = read(descripteur, pointeur,
   67:                         (longueur_residuelle > PIPE_BUF)
   68:                         ? PIPE_BUF : longueur_residuelle);
   69: 
   70:                 if ((longueur_lue == 0) &&
   71:                         (longueur_tampon == longueur_residuelle))
   72:                 {
   73:                     return(longueur_tampon - longueur_residuelle);
   74:                 }
   75: 
   76:                 if ((longueur_lue == -1) && (errno == EINTR))
   77:                 {
   78:                     nanosleep(&attente, NULL);
   79:                     drapeau = d_vrai;
   80:                 }
   81:                 else
   82:                 {
   83:                     drapeau = d_faux;
   84:                 }
   85:             } while(drapeau == d_vrai);
   86: 
   87:             if (longueur_lue != 0)
   88:             {
   89:                 if (longueur_lue < (longueur_residuelle > PIPE_BUF)
   90:                         ? PIPE_BUF : longueur_residuelle)
   91:                 {
   92:                     pointeur += longueur_lue;
   93:                     longueur_residuelle -= longueur_lue;
   94: 
   95:                     return(longueur_tampon - longueur_residuelle);
   96:                 }
   97:             }
   98:         }
   99: 
  100:         pointeur += longueur_lue;
  101:         longueur_residuelle -= longueur_lue;
  102:     }
  103: 
  104:     return(longueur_tampon - longueur_residuelle);
  105: }
  106: 
  107: 
  108: /*
  109: ================================================================================
  110:   Procédure d'écriture atomique
  111: ================================================================================
  112:   Entrée :
  113: --------------------------------------------------------------------------------
  114:   Sortie :
  115: --------------------------------------------------------------------------------
  116:   Effets de bord : néant
  117: ================================================================================
  118: */
  119: 
  120: ssize_t
  121: write_atomic(struct_processus *s_etat_processus,
  122:         int descripteur, void *tampon, size_t longueur_tampon)
  123: {
  124:     logical1            drapeau;
  125: 
  126:     size_t              longueur_residuelle;
  127:     ssize_t             longueur_ecrite;
  128: 
  129:     struct timespec     attente;
  130: 
  131:     void                *pointeur;
  132: 
  133:     longueur_residuelle = longueur_tampon;
  134:     pointeur = tampon;
  135: 
  136:     attente.tv_sec = 0;
  137:     attente.tv_nsec = GRANULARITE_us * 1000;
  138: 
  139:     while(longueur_residuelle != 0)
  140:     {
  141:         errno = 0;
  142:         longueur_ecrite = 0;
  143: 
  144:         while(longueur_ecrite == 0)
  145:         {
  146:             do
  147:             {
  148:                 longueur_ecrite = write(descripteur, pointeur,
  149:                         (longueur_residuelle > PIPE_BUF)
  150:                         ? PIPE_BUF : longueur_residuelle);
  151: 
  152:                 if (longueur_ecrite == -1)
  153:                 {
  154:                     if (errno == EINTR)
  155:                     {
  156:                         nanosleep(&attente, NULL);
  157:                         drapeau = d_vrai;
  158:                     }
  159:                     else // EPIPE
  160:                     {
  161:                         return(-1);
  162:                     }
  163:                 }
  164:                 else
  165:                 {
  166:                     drapeau = d_faux;
  167:                 }
  168:             } while(drapeau == d_vrai);
  169: 
  170:             if (longueur_ecrite == 0)
  171:             {
  172:                 nanosleep(&attente, NULL);
  173:             }
  174:         }
  175: 
  176:         pointeur += longueur_ecrite;
  177:         longueur_residuelle -= longueur_ecrite;
  178:     }
  179: 
  180:     return(longueur_tampon);
  181: }
  182: 
  183: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>