Changeset 7ce2483 for libcfa


Ignore:
Timestamp:
Oct 1, 2021, 8:22:31 AM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
96f01d7f
Parents:
056cbdb
Message:

formatting, remove release, and update lock/unlock for use with mutex statement

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/fstream.cfa

    r056cbdb r7ce2483  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Sep 21 21:51:38 2021
    13 // Update Count     : 460
     12// Last Modified On : Fri Oct  1 08:10:21 2021
     13// Update Count     : 473
    1414//
    1515
     
    2828#define IO_MSG "I/O error: "
    2929
    30 void ?{}( ofstream & os, void * file ) with(os) {
     30// private
     31void ?{}( ofstream & os, void * file ) with( os ) {
    3132        file$ = file;
    3233        sepDefault$ = true;
     
    4142} // ?{}
    4243
    43 // private
    44 bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
    45 void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
    46 void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
    47 const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
    48 void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
    49 bool getNL$( ofstream & os ) { return os.sawNL$; }
    50 void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
    51 bool getANL$( ofstream & os ) { return os.nlOnOff$; }
    52 bool getPrt$( ofstream & os ) { return os.prt$; }
    53 void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
     44inline bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; }
     45inline void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; }
     46inline void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; }
     47inline const char * sepGetCur$( ofstream & os ) { return os.sepCur$; }
     48inline void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; }
     49inline bool getNL$( ofstream & os ) { return os.sawNL$; }
     50inline void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; }
     51inline bool getANL$( ofstream & os ) { return os.nlOnOff$; }
     52inline bool getPrt$( ofstream & os ) { return os.prt$; }
     53inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; }
     54
     55inline void lock( ofstream & os ) with( os ) {  lock( os.lock$ ); }
     56inline void unlock( ofstream & os ) { unlock( os.lock$ ); }
    5457
    5558// public
    5659void ?{}( ofstream & os ) { os.file$ = 0p; }
    57 
    58 void ?{}( ofstream & os, const char name[], const char mode[] ) {
    59         open( os, name, mode );
    60 } // ?{}
    61 
    62 void ?{}( ofstream & os, const char name[] ) {
    63         open( os, name, "w" );
    64 } // ?{}
    65 
    66 void ^?{}( ofstream & os ) {
    67         close( os );
    68 } // ^?{}
     60void ?{}( ofstream & os, const char name[], const char mode[] ) { open( os, name, mode ); }
     61void ?{}( ofstream & os, const char name[] ) { open( os, name, "w" ); }
     62void ^?{}( ofstream & os ) { close( os ); }
    6963
    7064void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); }
     
    107101        if ( &os == &exit ) exit( EXIT_FAILURE );
    108102        if ( &os == &abort ) abort();
    109         if ( os.acquired$ ) { os.acquired$ = false; release( os ); }
     103        if ( os.acquired$ ) { os.acquired$ = false; unlock( os ); }
    110104} // ends
    111105
    112 bool fail( ofstream & os ) {
    113         return os.file$ == 0 || ferror( (FILE *)(os.file$) );
    114 } // fail
    115 
    116 void clear( ofstream & os ) {
    117         clearerr( (FILE *)(os.file$) );
    118 } // clear
    119 
    120 int flush( ofstream & os ) {
    121         return fflush( (FILE *)(os.file$) );
    122 } // flush
     106bool fail( ofstream & os ) { return os.file$ == 0 || ferror( (FILE *)(os.file$) ); }
     107void clear( ofstream & os ) { clearerr( (FILE *)(os.file$) ); }
     108int flush( ofstream & os ) { return fflush( (FILE *)(os.file$) ); }
    123109
    124110void open( ofstream & os, const char name[], const char mode[] ) {
     
    131117} // open
    132118
    133 void open( ofstream & os, const char name[] ) {
    134         open( os, name, "w" );
    135 } // open
    136 
    137 void close( ofstream & os ) with(os) {
     119void open( ofstream & os, const char name[] ) { open( os, name, "w" ); }
     120
     121void close( ofstream & os ) with( os ) {
    138122  if ( (FILE *)(file$) == 0p ) return;
    139123  if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return;
     
    143127                // abort | IO_MSG "close output" | nl | strerror( errno );
    144128        } // if
    145         file$ = 0p;
     129        file$ = 0p;                                                                                     // safety after close
    146130} // close
    147131
     
    175159} // fmt
    176160
    177 inline void acquire( ofstream & os ) with(os) {
    178         lock( lock$ );                                                                          // may increase recursive lock
     161void acquire( ofstream & os ) with( os ) {
     162        lock( os );                                                                                     // may increase recursive lock
    179163        if ( ! acquired$ ) acquired$ = true;                            // not locked ?
    180         else unlock( lock$ );                                                           // unwind recursive lock at start
     164        else unlock( os );                                                                      // unwind recursive lock at start
    181165} // acquire
    182166
    183 inline void release( ofstream & os ) {
    184         unlock( os.lock$ );
    185 } // release
    186 
    187 void ?{}( osacquire & acq, ofstream & os ) { lock( os.lock$ ); &acq.os = &os; }
    188 void ^?{}( osacquire & acq ) { release( acq.os ); }
     167void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os ); }
     168void ^?{}( osacquire & acq ) { unlock( acq.os ); }
    189169
    190170static ofstream soutFile = { (FILE *)stdout };
     
    205185        flush( os );
    206186        return os;
    207         // (ofstream &)(os | '\n');
    208         // setPrt$( os, false );                                                        // turn off
    209         // setNL$( os, true );
    210         // flush( os );
    211         // return sepOff( os );                                                 // prepare for next line
    212187} // nl
    213188
     
    217192
    218193// private
    219 void ?{}( ifstream & is, void * file ) with(is) {
     194void ?{}( ifstream & is, void * file ) with( is ) {
    220195        file$ = file;
    221196        nlOnOff$ = false;
     
    223198} // ?{}
    224199
     200inline void lock( ifstream & os ) with( os ) { lock( os.lock$ ); }
     201inline void unlock( ifstream & os ) { unlock( os.lock$ ); }
     202
    225203// public
    226204void ?{}( ifstream & is ) { is.file$ = 0p; }
    227 
    228 void ?{}( ifstream & is, const char name[], const char mode[] ) {
    229         open( is, name, mode );
    230 } // ?{}
    231 
    232 void ?{}( ifstream & is, const char name[] ) {
    233         open( is, name, "r" );
    234 } // ?{}
    235 
    236 void ^?{}( ifstream & is ) {
    237         close( is );
    238 } // ^?{}
     205void ?{}( ifstream & is, const char name[], const char mode[] ) { open( is, name, mode ); }
     206void ?{}( ifstream & is, const char name[] ) { open( is, name, "r" ); }
     207void ^?{}( ifstream & is ) { close( is ); }
    239208
    240209void nlOn( ifstream & os ) { os.nlOnOff$ = true; }
     
    242211bool getANL( ifstream & os ) { return os.nlOnOff$; }
    243212
    244 bool fail( ifstream & is ) {
    245         return is.file$ == 0p || ferror( (FILE *)(is.file$) );
    246 } // fail
    247 
    248 void clear( ifstream & is ) {
    249         clearerr( (FILE *)(is.file$) );
    250 } // clear
     213bool fail( ifstream & is ) { return is.file$ == 0p || ferror( (FILE *)(is.file$) ); }
     214void clear( ifstream & is ) { clearerr( (FILE *)(is.file$) ); }
    251215
    252216void ends( ifstream & is ) {
    253         if ( is.acquired$ ) { is.acquired$ = false; release( is ); }
     217        if ( is.acquired$ ) { is.acquired$ = false; unlock( is ); }
    254218} // ends
    255219
    256 bool eof( ifstream & is ) {
    257         return feof( (FILE *)(is.file$) );
    258 } // eof
     220bool eof( ifstream & is ) { return feof( (FILE *)(is.file$) ); }
    259221
    260222void open( ifstream & is, const char name[], const char mode[] ) {
     
    267229} // open
    268230
    269 void open( ifstream & is, const char name[] ) {
    270         open( is, name, "r" );
    271 } // open
    272 
    273 void close( ifstream & is ) with(is) {
     231void open( ifstream & is, const char name[] ) { open( is, name, "r" ); }
     232
     233void close( ifstream & is ) with( is ) {
    274234  if ( (FILE *)(file$) == 0p ) return;
    275235  if ( (FILE *)(file$) == (FILE *)stdin ) return;
     
    320280} // fmt
    321281
    322 inline void acquire( ifstream & is ) with(is) {
    323         lock( lock$ );                                                                          // may increase recursive lock
     282void acquire( ifstream & is ) with( is ) {
     283        lock( is );                                                                                     // may increase recursive lock
    324284        if ( ! acquired$ ) acquired$ = true;                            // not locked ?
    325         else unlock( lock$ );                                                           // unwind recursive lock at start
     285        else unlock( is );                                                                      // unwind recursive lock at start
    326286} // acquire
    327287
    328 inline void release( ifstream & is ) {
    329         unlock( is.lock$ );
    330 } // release
    331 
    332 void ?{}( isacquire & acq, ifstream & is ) { lock( is.lock$ ); &acq.is = &is; }
    333 void ^?{}( isacquire & acq ) { release( acq.is ); }
     288void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is ); }
     289void ^?{}( isacquire & acq ) { unlock( acq.is ); }
    334290
    335291static ifstream sinFile = { (FILE *)stdin };
  • libcfa/src/fstream.hfa

    r056cbdb r7ce2483  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 28 07:35:50 2021
    13 // Update Count     : 234
     12// Last Modified On : Fri Oct  1 07:40:37 2021
     13// Update Count     : 238
    1414//
    1515
     
    5353void setPrt$( ofstream &, bool );
    5454
     55void lock( ofstream & );
     56void unlock( ofstream & );
     57
    5558// public
    5659void sepOn( ofstream & );
     
    7881
    7982void acquire( ofstream & );
    80 void release( ofstream & );
    81 
    82 void lock( ofstream & );
    83 void unlock( ofstream & );
    8483
    8584struct osacquire {
     
    114113
    115114// Satisfies istream
     115
     116// private
     117void lock( ifstream & );
     118void unlock( ifstream & );
    116119
    117120// public
     
    132135
    133136void acquire( ifstream & is );
    134 void release( ifstream & is );
    135137
    136138struct isacquire {
Note: See TracChangeset for help on using the changeset viewer.