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