Annotation of rpl/src/operations_atomiques.c, revision 1.44
1.1 bertrand 1: /*
2: ================================================================================
1.43 bertrand 3: RPL/2 (R) version 4.1.13
1.42 bertrand 4: Copyright (C) 1989-2013 Dr. BERTRAND Joël
1.1 bertrand 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:
1.12 bertrand 23: #include "rpl-conv.h"
1.1 bertrand 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:
1.12 bertrand 38: ssize_t
1.1 bertrand 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: {
1.44 ! bertrand 73: return(((ssize_t) longueur_tampon) -
! 74: ((ssize_t) longueur_residuelle));
1.1 bertrand 75: }
76:
77: if ((longueur_lue == -1) && (errno == EINTR))
78: {
1.30 bertrand 79: scrutation_interruptions(s_etat_processus);
1.1 bertrand 80: nanosleep(&attente, NULL);
81: drapeau = d_vrai;
82: }
83: else
84: {
85: drapeau = d_faux;
86: }
87: } while(drapeau == d_vrai);
88:
89: if (longueur_lue != 0)
90: {
91: if (longueur_lue < (longueur_residuelle > PIPE_BUF)
92: ? PIPE_BUF : longueur_residuelle)
93: {
94: pointeur += longueur_lue;
1.44 ! bertrand 95: longueur_residuelle -= (size_t) longueur_lue;
1.1 bertrand 96:
1.44 ! bertrand 97: return(((ssize_t) longueur_tampon) -
! 98: ((ssize_t) longueur_residuelle));
1.1 bertrand 99: }
100: }
101: }
102:
103: pointeur += longueur_lue;
1.44 ! bertrand 104: longueur_residuelle -= (size_t) longueur_lue;
1.1 bertrand 105: }
106:
1.44 ! bertrand 107: return(((ssize_t) longueur_tampon) - ((ssize_t) longueur_residuelle));
1.1 bertrand 108: }
109:
110:
111: /*
112: ================================================================================
113: Procédure d'écriture atomique
114: ================================================================================
115: Entrée :
116: --------------------------------------------------------------------------------
117: Sortie :
118: --------------------------------------------------------------------------------
119: Effets de bord : néant
120: ================================================================================
121: */
122:
1.12 bertrand 123: ssize_t
1.1 bertrand 124: write_atomic(struct_processus *s_etat_processus,
125: int descripteur, void *tampon, size_t longueur_tampon)
126: {
127: logical1 drapeau;
128:
129: size_t longueur_residuelle;
130: ssize_t longueur_ecrite;
131:
132: struct timespec attente;
133:
134: void *pointeur;
135:
136: longueur_residuelle = longueur_tampon;
137: pointeur = tampon;
138:
139: attente.tv_sec = 0;
140: attente.tv_nsec = GRANULARITE_us * 1000;
141:
142: while(longueur_residuelle != 0)
143: {
144: errno = 0;
145: longueur_ecrite = 0;
146:
147: while(longueur_ecrite == 0)
148: {
149: do
150: {
151: longueur_ecrite = write(descripteur, pointeur,
152: (longueur_residuelle > PIPE_BUF)
153: ? PIPE_BUF : longueur_residuelle);
154:
155: if (longueur_ecrite == -1)
156: {
157: if (errno == EINTR)
158: {
1.30 bertrand 159: scrutation_interruptions(s_etat_processus);
1.1 bertrand 160: nanosleep(&attente, NULL);
161: drapeau = d_vrai;
162: }
163: else // EPIPE
164: {
165: return(-1);
166: }
167: }
168: else
169: {
170: drapeau = d_faux;
171: }
172: } while(drapeau == d_vrai);
173:
174: if (longueur_ecrite == 0)
175: {
1.30 bertrand 176: scrutation_interruptions(s_etat_processus);
1.1 bertrand 177: nanosleep(&attente, NULL);
178: }
179: }
180:
181: pointeur += longueur_ecrite;
1.44 ! bertrand 182: longueur_residuelle -= (size_t) longueur_ecrite;
1.1 bertrand 183: }
184:
1.44 ! bertrand 185: return((ssize_t) longueur_tampon);
1.1 bertrand 186: }
187:
188: // vim: ts=4
CVSweb interface <joel.bertrand@systella.fr>