Changeset 8dcb832
- Timestamp:
- Oct 6, 2021, 8:37:21 PM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 237df76
- Parents:
- e16eb460
- Location:
- libcfa/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
re16eb460 r8dcb832 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Oct 1 08:10:21202113 // Update Count : 47312 // Last Modified On : Wed Oct 6 18:39:13 2021 13 // Update Count : 508 14 14 // 15 15 … … 36 36 prt$ = false; 37 37 sawNL$ = false; 38 acquired$ = false;39 38 sepSetCur$( os, sepGet( os ) ); 40 39 sepSet( os, " " ); … … 101 100 if ( &os == &exit ) exit( EXIT_FAILURE ); 102 101 if ( &os == &abort ) abort(); 103 if ( os.acquired$ ) { os.acquired$ = false; unlock( os ); }104 102 } // ends 105 103 … … 109 107 110 108 void open( ofstream & os, const char name[], const char mode[] ) { 111 FILE * file = fopen( name, mode ); 109 FILE * file; 110 for ( cnt; 10 ) { 111 errno = 0; 112 file = fopen( name, mode ); 113 if ( file != 0p || errno != EINTR ) break; // timer interrupt ? 114 if ( cnt == 9 ) abort( "ofstream open EINTR spinning exceeded" ); 115 } // for 112 116 if ( file == 0p ) { 113 117 throw (Open_Failure){ os }; … … 123 127 if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return; 124 128 125 if ( fclose( (FILE *)(file$) ) == EOF ) { 129 int ret; 130 for ( cnt; 10 ) { 131 errno = 0; 132 ret = fclose( (FILE *)(file$) ); 133 if ( ret != EOF || errno != EINTR ) break; // timer interrupt ? 134 if ( cnt == 9 ) abort( "ofstream open EINTR spinning exceeded" ); 135 } // for 136 if ( ret == EOF ) { 126 137 throw (Close_Failure){ os }; 127 138 // abort | IO_MSG "close output" | nl | strerror( errno ); … … 146 157 va_list args; 147 158 va_start( args, format ); 148 int len = vfprintf( (FILE *)(os.file$), format, args ); 159 160 int len; 161 for ( cnt; 10 ) { 162 errno = 0; 163 len = vfprintf( (FILE *)(os.file$), format, args ); 164 if ( len != EOF || errno != EINTR ) break; // timer interrupt ? 165 if ( cnt == 9 ) abort( "ofstream fmt EINTR spinning exceeded" ); 166 } // for 149 167 if ( len == EOF ) { 150 168 if ( ferror( (FILE *)(os.file$) ) ) { … … 158 176 return len; 159 177 } // fmt 160 161 void acquire( ofstream & os ) with( os ) {162 lock( os ); // may increase recursive lock163 if ( ! acquired$ ) acquired$ = true; // not locked ?164 else unlock( os ); // unwind recursive lock at start165 } // acquire166 167 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os ); }168 void ^?{}( osacquire & acq ) { unlock( acq.os ); }169 178 170 179 static ofstream soutFile = { (FILE *)stdout }; … … 195 204 file$ = file; 196 205 nlOnOff$ = false; 197 acquired$ = false;198 206 } // ?{} 199 207 … … 215 223 216 224 void ends( ifstream & is ) { 217 if ( is.acquired$ ) { is.acquired$ = false; unlock( is ); }218 225 } // ends 219 226 … … 221 228 222 229 void open( ifstream & is, const char name[], const char mode[] ) { 223 FILE * file = fopen( name, mode ); 230 FILE * file; 231 for ( cnt; 10 ) { 232 errno = 0; 233 file = fopen( name, mode ); 234 if ( file != 0p || errno != EINTR ) break; // timer interrupt ? 235 if ( cnt == 9 ) abort( "ifstream open EINTR spinning exceeded" ); 236 } // for 224 237 if ( file == 0p ) { 225 238 throw (Open_Failure){ is }; … … 235 248 if ( (FILE *)(file$) == (FILE *)stdin ) return; 236 249 237 if ( fclose( (FILE *)(file$) ) == EOF ) { 250 int ret; 251 for ( cnt; 10 ) { 252 errno = 0; 253 ret = fclose( (FILE *)(file$) ); 254 if ( ret != EOF || errno != EINTR ) break; // timer interrupt ? 255 if ( cnt == 9 ) abort( "ifstream close EINTR spinning exceeded" ); 256 } // for 257 if ( ret == EOF ) { 238 258 throw (Close_Failure){ is }; 239 259 // abort | IO_MSG "close input" | nl | strerror( errno ); 240 260 } // if 241 file$ = 0p; 261 file$ = 0p; // safety after close 242 262 } // close 243 263 … … 268 288 int fmt( ifstream & is, const char format[], ... ) { 269 289 va_list args; 270 271 290 va_start( args, format ); 272 int len = vfscanf( (FILE *)(is.file$), format, args ); 291 292 int len; 293 for () { // no check for EINTR limit waiting for keyboard input 294 errno = 0; 295 len = vfscanf( (FILE *)(is.file$), format, args ); 296 if ( len != EOF || errno != EINTR ) break; // timer interrupt ? 297 } // for 273 298 if ( len == EOF ) { 274 299 if ( ferror( (FILE *)(is.file$) ) ) { … … 279 304 return len; 280 305 } // fmt 281 282 void acquire( ifstream & is ) with( is ) {283 lock( is ); // may increase recursive lock284 if ( ! acquired$ ) acquired$ = true; // not locked ?285 else unlock( is ); // unwind recursive lock at start286 } // acquire287 288 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is ); }289 void ^?{}( isacquire & acq ) { unlock( acq.is ); }290 306 291 307 static ifstream sinFile = { (FILE *)stdin }; -
libcfa/src/fstream.hfa
re16eb460 r8dcb832 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Oct 1 07:40:37202113 // Update Count : 2 3812 // Last Modified On : Wed Oct 6 18:45:49 2021 13 // Update Count : 240 14 14 // 15 15 … … 36 36 char tupleSeparator$[ofstream_sepSize]; 37 37 multiple_acquisition_lock lock$; 38 bool acquired$;39 38 }; // ofstream 40 39 … … 80 79 ofstream & write( ofstream &, const char data[], size_t size ); 81 80 82 void acquire( ofstream & );83 84 struct osacquire {85 ofstream & os;86 };87 void ?{}( osacquire & acq, ofstream & );88 void ^?{}( osacquire & acq );89 90 81 void ?{}( ofstream & ); 91 82 void ?{}( ofstream &, const char name[], const char mode[] ); // FIX ME: use default = "w" … … 109 100 bool nlOnOff$; 110 101 multiple_acquisition_lock lock$; 111 bool acquired$;112 102 }; // ifstream 113 103 … … 133 123 ifstream & read( ifstream & is, char data[], size_t size ); 134 124 ifstream & ungetc( ifstream & is, char c ); 135 136 void acquire( ifstream & is );137 138 struct isacquire {139 ifstream & is;140 };141 void ?{}( isacquire & acq, ifstream & is );142 void ^?{}( isacquire & acq );143 125 144 126 void ?{}( ifstream & is ); -
libcfa/src/iostream.cfa
re16eb460 r8dcb832 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat May 15 09:39:21202113 // Update Count : 134 212 // Last Modified On : Wed Oct 6 18:55:03 2021 13 // Update Count : 1344 14 14 // 15 15 … … 398 398 return os; 399 399 } // nlOff 400 } // distribution401 402 forall( ostype & | ostream( ostype ) ) {403 ostype & acquire( ostype & os ) {404 acquire( os ); // call void returning405 return os;406 } // acquire407 400 } // distribution 408 401 … … 1037 1030 } // distribution 1038 1031 1039 forall( istype & | istream( istype ) ) {1040 istype & acquire( istype & is ) {1041 acquire( is ); // call void returning1042 return is;1043 } // acquire1044 } // distribution1045 1046 1032 // *********************************** manipulators *********************************** 1047 1033 -
libcfa/src/iostream.hfa
re16eb460 r8dcb832 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 28 20:37:56202113 // Update Count : 40 112 // Last Modified On : Wed Oct 6 18:54:59 2021 13 // Update Count : 404 14 14 // 15 15 … … 58 58 void close( ostype & ); 59 59 ostype & write( ostype &, const char [], size_t ); 60 void acquire( ostype & ); // concurrent access61 60 }; // ostream 62 61 … … 142 141 ostype & nlOn( ostype & ); 143 142 ostype & nlOff( ostype & ); 144 } // distribution145 146 forall( ostype & | ostream( ostype ) ) {147 ostype & acquire( ostype & );148 143 } // distribution 149 144 … … 312 307 void close( istype & is ); 313 308 istype & read( istype &, char [], size_t ); 314 void acquire( istype & ); // concurrent access315 309 }; // istream 316 310 … … 379 373 } // distribution 380 374 381 forall( istype & | istream( istype ) ) {382 istype & acquire( istype & );383 } // distribution384 385 375 // *********************************** manipulators *********************************** 386 376
Note: See TracChangeset
for help on using the changeset viewer.