Changeset bbe1a87


Ignore:
Timestamp:
Jul 3, 2018, 9:07:31 AM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer
Children:
9459c01, e3b2474
Parents:
4c3ee8d
Message:

use distribution for SC qualifiers, and inline routines

Location:
src/libcfa
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/clock

    r4c3ee8d rbbe1a87  
    1010// Created On       : Thu Apr 12 14:36:06 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jun 26 14:11:44 2018
    13 // Update Count     : 6
     12// Last Modified On : Mon Jul  2 21:40:01 2018
     13// Update Count     : 7
    1414//
    1515
     
    3434};
    3535
    36 static inline void resetClock( Clock & clk ) with( clk ) {
    37         clocktype = CLOCK_REALTIME_COARSE;
    38 } // Clock::resetClock
     36static inline {
     37        void resetClock( Clock & clk ) with( clk ) {
     38                clocktype = CLOCK_REALTIME_COARSE;
     39        } // Clock::resetClock
    3940
    40 static inline void resetClock( Clock & clk, Duration adj ) with( clk ) {
    41         clocktype = -1;
    42         offset = adj + __timezone`s;                                                    // timezone (global) is (UTC - local time) in seconds
    43 } // resetClock
     41        void resetClock( Clock & clk, Duration adj ) with( clk ) {
     42                clocktype = -1;
     43                offset = adj + __timezone`s;                                    // timezone (global) is (UTC - local time) in seconds
     44        } // resetClock
    4445
    45 static inline void ?{}( Clock & clk ) { resetClock( clk ); }
    46 static inline void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }
     46        void ?{}( Clock & clk ) { resetClock( clk ); }
     47        void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }
    4748
    48 static inline Duration getResNsec() {
    49         struct timespec res;
    50         clock_getres( CLOCK_REALTIME, &res );
    51         return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    52 } // getRes
     49        Duration getResNsec() {
     50                struct timespec res;
     51                clock_getres( CLOCK_REALTIME, &res );
     52                return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
     53        } // getRes
    5354
    54 static inline Duration getRes() {
    55         struct timespec res;
    56         clock_getres( CLOCK_REALTIME_COARSE, &res );
    57         return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    58 } // getRes
     55        Duration getRes() {
     56                struct timespec res;
     57                clock_getres( CLOCK_REALTIME_COARSE, &res );
     58                return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
     59        } // getRes
    5960
    60 static inline Time getTimeNsec() {                                              // with nanoseconds
    61         timespec curr;
    62         clock_gettime( CLOCK_REALTIME, &curr );
    63         return (Time){ curr };
    64 } // getTime
     61        Time getTimeNsec() {                                                            // with nanoseconds
     62                timespec curr;
     63                clock_gettime( CLOCK_REALTIME, &curr );
     64                return (Time){ curr };
     65        } // getTime
    6566
    66 static inline Time getTime() {                                                  // without nanoseconds
    67         timespec curr;
    68         clock_gettime( CLOCK_REALTIME_COARSE, &curr );
    69         curr.tv_nsec = 0;
    70         return (Time){ curr };
    71 } // getTime
     67        Time getTime() {                                                                        // without nanoseconds
     68                timespec curr;
     69                clock_gettime( CLOCK_REALTIME_COARSE, &curr );
     70                curr.tv_nsec = 0;
     71                return (Time){ curr };
     72        } // getTime
    7273
    73 static inline Time getTime( Clock & clk ) with( clk ) {
    74         return getTime() + offset;
    75 } // getTime
     74        Time getTime( Clock & clk ) with( clk ) {
     75                return getTime() + offset;
     76        } // getTime
    7677
    77 static inline Time ?()( Clock & clk ) with( clk ) {             // alternative syntax
    78         return getTime() + offset;
    79 } // getTime
     78        Time ?()( Clock & clk ) with( clk ) {                           // alternative syntax
     79                return getTime() + offset;
     80        } // getTime
    8081
    81 static inline timeval getTime( Clock & clk ) {
    82         return (timeval){ clk() };
    83 } // getTime
     82        timeval getTime( Clock & clk ) {
     83                return (timeval){ clk() };
     84        } // getTime
    8485
    85 static inline tm getTime( Clock & clk ) with( clk ) {
    86         tm ret;
    87         localtime_r( getTime( clk ).tv_sec, &ret );
    88         return ret;
    89 } // getTime
     86        tm getTime( Clock & clk ) with( clk ) {
     87                tm ret;
     88                localtime_r( getTime( clk ).tv_sec, &ret );
     89                return ret;
     90        } // getTime
     91} // distribution
    9092
    9193// Local Variables: //
  • src/libcfa/stdlib

    r4c3ee8d rbbe1a87  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  2 08:46:35 2018
    13 // Update Count     : 306
     12// Last Modified On : Tue Jul  3 08:17:28 2018
     13// Update Count     : 324
    1414//
    1515
     
    264264//---------------------------------------
    265265
    266 extern "C" { void srandom( unsigned int seed ); }               // override C version
    267 char random( void );
    268 char random( char u );
    269 char random( char l, char u );
    270 int random( void );
    271 int random( int u );
    272 int random( int l, int u );
    273 unsigned int random( void );
    274 unsigned int random( unsigned int u );
    275 unsigned int random( unsigned int l, unsigned int u );
    276 extern "C" { long int random( void ); }                                 // override C version
    277 long int random( long int u );
    278 long int random( long int l, long int u );
    279 unsigned long int random( void );
    280 unsigned long int random( unsigned long int u );
    281 unsigned long int random( unsigned long int l, unsigned long int u );
    282 float random( void );
    283 double random( void );
    284 float _Complex random( void );
    285 double _Complex random( void );
    286 long double _Complex random( void );
     266extern "C" {                                                                                    // override C version
     267        void srandom( unsigned int seed );
     268        long int random( void );
     269} // extern "C"
     270
     271static inline {
     272        long int random( long int l, long int u ) { if ( u < l ) [u, l] = [l, u]; return lrand48() % (u - l) + l; } // [l,u)
     273        long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); } // [0,u)
     274        unsigned long int random( void ) { return lrand48(); }
     275        unsigned long int random( unsigned long int l, unsigned long int u ) { if ( u < l ) [u, l] = [l, u]; return lrand48() % (u - l) + l; } // [l,u)
     276        unsigned long int random( unsigned long int u ) { return lrand48() % u; } // [0,u)
     277
     278        char random( void ) { return (unsigned long int)random(); }
     279        char random( char u ) { return random( (unsigned long int)u ); } // [0,u)
     280        char random( char l, char u ) { return random( (unsigned long int)l, (unsigned long int)u ); } // [l,u)
     281        int random( void ) { return (long int)random(); }
     282        int random( int u ) { return random( (long int)u ); } // [0,u]
     283        int random( int l, int u ) { return random( (long int)l, (long int)u ); } // [l,u)
     284        unsigned int random( void ) { return (unsigned long int)random(); }
     285        unsigned int random( unsigned int u ) { return random( (unsigned long int)u ); } // [0,u]
     286        unsigned int random( unsigned int l, unsigned int u ) { return random( (unsigned long int)l, (unsigned long int)u ); } // [l,u)
     287} // distribution
     288
     289float random( void );                                                                   // [0.0, 1.0)
     290double random( void );                                                                  // [0.0, 1.0)
     291float _Complex random( void );                                                  // [0.0, 1.0)+[0.0, 1.0)i
     292double _Complex random( void );                                                 // [0.0, 1.0)+[0.0, 1.0)i
     293long double _Complex random( void );                                    // [0.0, 1.0)+[0.0, 1.0)i
    287294
    288295//---------------------------------------
  • src/libcfa/stdlib.c

    r4c3ee8d rbbe1a87  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun  2 06:15:05 2018
    13 // Update Count     : 448
     12// Last Modified On : Tue Jul  3 08:17:30 2018
     13// Update Count     : 457
    1414//
    1515
     
    249249//---------------------------------------
    250250
    251 extern "C" { void srandom( unsigned int seed ) { srand48( (long int)seed ); } } // override C version
    252 char random( void ) { return (unsigned long int)random(); }
    253 char random( char u ) { return random( (unsigned long int)u ); }
    254 char random( char l, char u ) { return random( (unsigned long int)l, (unsigned long int)u ); }
    255 int random( void ) { return (long int)random(); }
    256 int random( int u ) { return random( (long int)u ); }
    257 int random( int l, int u ) { return random( (long int)l, (long int)u ); }
    258 unsigned int random( void ) { return (unsigned long int)random(); }
    259 unsigned int random( unsigned int u ) { return random( (unsigned long int)u ); }
    260 unsigned int random( unsigned int l, unsigned int u ) { return random( (unsigned long int)l, (unsigned long int)u ); }
    261 extern "C" { long int random( void ) { return mrand48(); } } // override C version
    262 long int random( long int u ) { if ( u < 0 ) return random( u, 0 ); else return random( 0, u ); }
    263 long int random( long int l, long int u ) { assert( l < u ); return lrand48() % (u - l) + l; }
    264 unsigned long int random( void ) { return lrand48(); }
    265 unsigned long int random( unsigned long int u ) { return lrand48() % u; }
    266 unsigned long int random( unsigned long int l, unsigned long int u ) { assert( l < u ); return lrand48() % (u - l) + l; }
     251extern "C" {                                                                                    // override C version
     252        void srandom( unsigned int seed ) { srand48( (long int)seed ); }
     253        long int random( void ) { return mrand48(); }
     254} // extern "C"
     255
    267256float random( void ) { return (float)drand48(); }               // cast otherwise float uses lrand48
    268257double random( void ) { return drand48(); }
  • src/libcfa/time

    r4c3ee8d rbbe1a87  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Apr 14 17:48:23 2018
    13 // Update Count     : 636
     12// Last Modified On : Mon Jul  2 21:28:38 2018
     13// Update Count     : 641
    1414//
    1515
     
    2727enum { TIMEGRAN = 1_000_000_000LL };                                    // nanosecond granularity, except for timeval
    2828
    29 
    3029//######################### Duration #########################
    3130
    32 static inline Duration ?=?( Duration & dur, zero_t ) { return dur{ 0 }; }
    33 
    34 static inline Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; }
    35 static inline Duration ?+?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv + rhs.tv }; }
    36 static inline Duration ?+=?( Duration & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; }
    37 
    38 static inline Duration -?( Duration rhs ) with( rhs ) { return (Duration)@{ -tv }; }
    39 static inline Duration ?-?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; }
    40 static inline Duration ?-=?( Duration & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; }
    41 
    42 static inline Duration ?*?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv * rhs }; }
    43 static inline Duration ?*?( int64_t lhs, Duration rhs ) { return (Duration)@{ lhs * rhs.tv }; }
    44 static inline Duration ?*=?( Duration & lhs, int64_t rhs ) { lhs = lhs * rhs; return lhs; }
    45 
    46 static inline int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; }
    47 static inline Duration ?/?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv / rhs }; }
    48 static inline Duration ?/=?( Duration & lhs, int64_t rhs ) { lhs = lhs / rhs; return lhs; }
    49 static inline double div( Duration lhs, Duration rhs ) { return (double)lhs.tv / (double)rhs.tv; }
    50 
    51 static inline Duration ?%?( Duration lhs, Duration rhs ) { return (Duration)@{ lhs.tv % rhs.tv }; }
    52 static inline Duration ?%=?( Duration & lhs, Duration rhs ) { lhs = lhs % rhs; return lhs; }
    53 
    54 static inline _Bool ?==?( Duration lhs, Duration rhs ) { return lhs.tv == rhs.tv; }
    55 static inline _Bool ?!=?( Duration lhs, Duration rhs ) { return lhs.tv != rhs.tv; }
    56 static inline _Bool ?<? ( Duration lhs, Duration rhs ) { return lhs.tv <  rhs.tv; }
    57 static inline _Bool ?<=?( Duration lhs, Duration rhs ) { return lhs.tv <= rhs.tv; }
    58 static inline _Bool ?>? ( Duration lhs, Duration rhs ) { return lhs.tv >  rhs.tv; }
    59 static inline _Bool ?>=?( Duration lhs, Duration rhs ) { return lhs.tv >= rhs.tv; }
    60 
    61 static inline _Bool ?==?( Duration lhs, zero_t ) { return lhs.tv == 0; }
    62 static inline _Bool ?!=?( Duration lhs, zero_t ) { return lhs.tv != 0; }
    63 static inline _Bool ?<? ( Duration lhs, zero_t ) { return lhs.tv <  0; }
    64 static inline _Bool ?<=?( Duration lhs, zero_t ) { return lhs.tv <= 0; }
    65 static inline _Bool ?>? ( Duration lhs, zero_t ) { return lhs.tv >  0; }
    66 static inline _Bool ?>=?( Duration lhs, zero_t ) { return lhs.tv >= 0; }
    67 
    68 static inline Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; }
    69 
    70 static inline Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; }
    71 static inline Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; }
    72 static inline Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; }
    73 static inline Duration ?`s( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; }
    74 static inline Duration ?`s( double sec ) { return (Duration)@{ sec * TIMEGRAN }; }
    75 static inline Duration ?`m( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
    76 static inline Duration ?`m( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
    77 static inline Duration ?`h( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
    78 static inline Duration ?`h( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
    79 static inline Duration ?`d( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
    80 static inline Duration ?`d( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
    81 static inline Duration ?`w( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    82 static inline Duration ?`w( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    83 
    84 static inline int64_t ?`ns( Duration dur ) { return dur.tv; }
    85 static inline int64_t ?`us( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000_000LL); }
    86 static inline int64_t ?`ms( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000LL); }
    87 static inline int64_t ?`s( Duration dur ) { return dur.tv / TIMEGRAN; }
    88 static inline int64_t ?`m( Duration dur ) { return dur.tv / (60LL * TIMEGRAN); }
    89 static inline int64_t ?`h( Duration dur ) { return dur.tv / (60LL * 60LL * TIMEGRAN); }
    90 static inline int64_t ?`d( Duration dur ) { return dur.tv / (24LL * 60LL * 60LL * TIMEGRAN); }
    91 static inline int64_t ?`w( Duration dur ) { return dur.tv / (7LL * 24LL * 60LL * 60LL * TIMEGRAN); }
    92 
    93 static inline Duration max( Duration lhs, Duration rhs ) { return  (lhs.tv < rhs.tv) ? rhs : lhs;}
    94 static inline Duration min( Duration lhs, Duration rhs ) { return !(rhs.tv < lhs.tv) ? lhs : rhs;}
    95 
     31static inline {
     32        Duration ?=?( Duration & dur, zero_t ) { return dur{ 0 }; }
     33
     34        Duration +?( Duration rhs ) with( rhs ) {       return (Duration)@{ +tv }; }
     35        Duration ?+?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv + rhs.tv }; }
     36        Duration ?+=?( Duration & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; }
     37
     38        Duration -?( Duration rhs ) with( rhs ) { return (Duration)@{ -tv }; }
     39        Duration ?-?( Duration & lhs, Duration rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; }
     40        Duration ?-=?( Duration & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; }
     41
     42        Duration ?*?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv * rhs }; }
     43        Duration ?*?( int64_t lhs, Duration rhs ) { return (Duration)@{ lhs * rhs.tv }; }
     44        Duration ?*=?( Duration & lhs, int64_t rhs ) { lhs = lhs * rhs; return lhs; }
     45
     46        int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; }
     47        Duration ?/?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv / rhs }; }
     48        Duration ?/=?( Duration & lhs, int64_t rhs ) { lhs = lhs / rhs; return lhs; }
     49        double div( Duration lhs, Duration rhs ) { return (double)lhs.tv / (double)rhs.tv; }
     50
     51        Duration ?%?( Duration lhs, Duration rhs ) { return (Duration)@{ lhs.tv % rhs.tv }; }
     52        Duration ?%=?( Duration & lhs, Duration rhs ) { lhs = lhs % rhs; return lhs; }
     53
     54        _Bool ?==?( Duration lhs, Duration rhs ) { return lhs.tv == rhs.tv; }
     55        _Bool ?!=?( Duration lhs, Duration rhs ) { return lhs.tv != rhs.tv; }
     56        _Bool ?<? ( Duration lhs, Duration rhs ) { return lhs.tv <  rhs.tv; }
     57        _Bool ?<=?( Duration lhs, Duration rhs ) { return lhs.tv <= rhs.tv; }
     58        _Bool ?>? ( Duration lhs, Duration rhs ) { return lhs.tv >  rhs.tv; }
     59        _Bool ?>=?( Duration lhs, Duration rhs ) { return lhs.tv >= rhs.tv; }
     60
     61        _Bool ?==?( Duration lhs, zero_t ) { return lhs.tv == 0; }
     62        _Bool ?!=?( Duration lhs, zero_t ) { return lhs.tv != 0; }
     63        _Bool ?<? ( Duration lhs, zero_t ) { return lhs.tv <  0; }
     64        _Bool ?<=?( Duration lhs, zero_t ) { return lhs.tv <= 0; }
     65        _Bool ?>? ( Duration lhs, zero_t ) { return lhs.tv >  0; }
     66        _Bool ?>=?( Duration lhs, zero_t ) { return lhs.tv >= 0; }
     67
     68        Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; }
     69
     70        Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; }
     71        Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; }
     72        Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; }
     73        Duration ?`s( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; }
     74        Duration ?`s( double sec ) { return (Duration)@{ sec * TIMEGRAN }; }
     75        Duration ?`m( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
     76        Duration ?`m( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
     77        Duration ?`h( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
     78        Duration ?`h( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
     79        Duration ?`d( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
     80        Duration ?`d( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
     81        Duration ?`w( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
     82        Duration ?`w( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
     83
     84        int64_t ?`ns( Duration dur ) { return dur.tv; }
     85        int64_t ?`us( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000_000LL); }
     86        int64_t ?`ms( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000LL); }
     87        int64_t ?`s( Duration dur ) { return dur.tv / TIMEGRAN; }
     88        int64_t ?`m( Duration dur ) { return dur.tv / (60LL * TIMEGRAN); }
     89        int64_t ?`h( Duration dur ) { return dur.tv / (60LL * 60LL * TIMEGRAN); }
     90        int64_t ?`d( Duration dur ) { return dur.tv / (24LL * 60LL * 60LL * TIMEGRAN); }
     91        int64_t ?`w( Duration dur ) { return dur.tv / (7LL * 24LL * 60LL * 60LL * TIMEGRAN); }
     92
     93        Duration max( Duration lhs, Duration rhs ) { return  (lhs.tv < rhs.tv) ? rhs : lhs;}
     94        Duration min( Duration lhs, Duration rhs ) { return !(rhs.tv < lhs.tv) ? lhs : rhs;}
     95} // distribution
    9696
    9797//######################### C timeval #########################
    9898
    99 static inline void ?{}( timeval & t ) {}
    100 static inline void ?{}( timeval & t, time_t sec, suseconds_t usec ) { t.tv_sec = sec; t.tv_usec = usec; }
    101 static inline void ?{}( timeval & t, time_t sec ) { t{ sec, 0 }; }
    102 static inline void ?{}( timeval & t, zero_t ) { t{ 0, 0 }; }
    103 static inline timeval ?=?( timeval & t, zero_t ) { return t{ 0 }; }
    104 static inline timeval ?+?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_usec + rhs.tv_usec }; }
    105 static inline timeval ?-?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_usec - rhs.tv_usec }; }
    106 static inline _Bool ?==?( timeval lhs, timeval rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_usec == rhs.tv_usec; }
    107 static inline _Bool ?!=?( timeval lhs, timeval rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_usec != rhs.tv_usec; }
    108 
     99static inline {
     100        void ?{}( timeval & t ) {}
     101        void ?{}( timeval & t, time_t sec, suseconds_t usec ) { t.tv_sec = sec; t.tv_usec = usec; }
     102        void ?{}( timeval & t, time_t sec ) { t{ sec, 0 }; }
     103        void ?{}( timeval & t, zero_t ) { t{ 0, 0 }; }
     104
     105        timeval ?=?( timeval & t, zero_t ) { return t{ 0 }; }
     106        timeval ?+?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_usec + rhs.tv_usec }; }
     107        timeval ?-?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_usec - rhs.tv_usec }; }
     108        _Bool ?==?( timeval lhs, timeval rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_usec == rhs.tv_usec; }
     109        _Bool ?!=?( timeval lhs, timeval rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_usec != rhs.tv_usec; }
     110} // distribution
    109111
    110112//######################### C timespec #########################
    111113
    112 static inline void ?{}( timespec & t ) {}
    113 static inline void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ) { t.tv_sec = sec; t.tv_nsec = nsec; }
    114 static inline void ?{}( timespec & t, time_t sec ) { t{ sec, 0}; }
    115 static inline void ?{}( timespec & t, zero_t ) { t{ 0, 0 }; }
    116 static inline timespec ?=?( timespec & t, zero_t ) { return t{ 0 }; }
    117 static inline timespec ?+?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_nsec + rhs.tv_nsec }; }
    118 static inline timespec ?-?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_nsec - rhs.tv_nsec }; }
    119 static inline _Bool ?==?( timespec lhs, timespec rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_nsec == rhs.tv_nsec; }
    120 static inline _Bool ?!=?( timespec lhs, timespec rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_nsec != rhs.tv_nsec; }
    121 
     114static inline {
     115        void ?{}( timespec & t ) {}
     116        void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ) { t.tv_sec = sec; t.tv_nsec = nsec; }
     117        void ?{}( timespec & t, time_t sec ) { t{ sec, 0}; }
     118        void ?{}( timespec & t, zero_t ) { t{ 0, 0 }; }
     119
     120        timespec ?=?( timespec & t, zero_t ) { return t{ 0 }; }
     121        timespec ?+?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_nsec + rhs.tv_nsec }; }
     122        timespec ?-?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec - rhs.tv_sec, lhs.tv_nsec - rhs.tv_nsec }; }
     123        _Bool ?==?( timespec lhs, timespec rhs ) { return lhs.tv_sec == rhs.tv_sec && lhs.tv_nsec == rhs.tv_nsec; }
     124        _Bool ?!=?( timespec lhs, timespec rhs ) { return lhs.tv_sec != rhs.tv_sec || lhs.tv_nsec != rhs.tv_nsec; }
     125} // distribution
    122126
    123127//######################### C itimerval #########################
    124128
    125 static inline void ?{}( itimerval & itv, Duration alarm ) with( itv ) {
    126         // itimerval contains durations but but uses time data-structure timeval.
    127         it_value{ alarm`s, (alarm % 1`s)`us };                          // seconds, microseconds
    128         it_interval{ 0 };                                                                       // 0 seconds, 0 microseconds
    129 } // itimerval
    130 
    131 static inline void ?{}( itimerval & itv, Duration alarm, Duration interval ) with( itv ) {
    132         // itimerval contains durations but but uses time data-structure timeval.
    133         it_value{ alarm`s, (alarm % 1`s)`us };                          // seconds, microseconds
    134         it_interval{ interval`s, interval`us };                         // seconds, microseconds
    135 } // itimerval
    136 
     129static inline {
     130        void ?{}( itimerval & itv, Duration alarm ) with( itv ) {
     131                // itimerval contains durations but but uses time data-structure timeval.
     132                it_value{ alarm`s, (alarm % 1`s)`us };                  // seconds, microseconds
     133                it_interval{ 0 };                                                               // 0 seconds, 0 microseconds
     134        } // itimerval
     135
     136        void ?{}( itimerval & itv, Duration alarm, Duration interval ) with( itv ) {
     137                // itimerval contains durations but but uses time data-structure timeval.
     138                it_value{ alarm`s, (alarm % 1`s)`us };                  // seconds, microseconds
     139                it_interval{ interval`s, interval`us };                 // seconds, microseconds
     140        } // itimerval
     141} // distribution
    137142
    138143//######################### Time #########################
    139144
    140145void ?{}( Time & time, int year, int month = 0, int day = 0, int hour = 0, int min = 0, int sec = 0, int nsec = 0 );
    141 static inline Time ?=?( Time & time, zero_t ) { return time{ 0 }; }
    142 
    143 static inline void ?{}( Time & time, timeval t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; }
    144 static inline Time ?=?( Time & time, timeval t ) with( time ) {
    145         tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL);
    146         return time;
    147 } // ?=?
    148 
    149 static inline void ?{}( Time & time, timespec t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; }
    150 static inline Time ?=?( Time & time, timespec t ) with( time ) {
    151         tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;
    152         return time;
    153 } // ?=?
    154 
    155 static inline Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; }
    156 static inline Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; }
    157 static inline Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; }
    158 
    159 static inline Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; }
    160 static inline Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; }
    161 static inline Time ?-=?( Time & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; }
    162 static inline _Bool ?==?( Time lhs, Time rhs ) { return lhs.tv == rhs.tv; }
    163 static inline _Bool ?!=?( Time lhs, Time rhs ) { return lhs.tv != rhs.tv; }
    164 static inline _Bool ?<?( Time lhs, Time rhs ) { return lhs.tv < rhs.tv; }
    165 static inline _Bool ?<=?( Time lhs, Time rhs ) { return lhs.tv <= rhs.tv; }
    166 static inline _Bool ?>?( Time lhs, Time rhs ) { return lhs.tv > rhs.tv; }
    167 static inline _Bool ?>=?( Time lhs, Time rhs ) { return lhs.tv >= rhs.tv; }
     146static inline {
     147        Time ?=?( Time & time, zero_t ) { return time{ 0 }; }
     148
     149        void ?{}( Time & time, timeval t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; }
     150        Time ?=?( Time & time, timeval t ) with( time ) {
     151                tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL);
     152                return time;
     153        } // ?=?
     154
     155        void ?{}( Time & time, timespec t ) with( time ) { tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; }
     156        Time ?=?( Time & time, timespec t ) with( time ) {
     157                tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;
     158                return time;
     159        } // ?=?
     160
     161        Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; }
     162        Time ?+?( Duration lhs, Time rhs ) { return rhs + lhs; }
     163        Time ?+=?( Time & lhs, Duration rhs ) { lhs = lhs + rhs; return lhs; }
     164
     165        Duration ?-?( Time lhs, Time rhs ) { return (Duration)@{ lhs.tv - rhs.tv }; }
     166        Time ?-?( Time lhs, Duration rhs ) { return (Time)@{ lhs.tv - rhs.tv }; }
     167        Time ?-=?( Time & lhs, Duration rhs ) { lhs = lhs - rhs; return lhs; }
     168        _Bool ?==?( Time lhs, Time rhs ) { return lhs.tv == rhs.tv; }
     169        _Bool ?!=?( Time lhs, Time rhs ) { return lhs.tv != rhs.tv; }
     170        _Bool ?<?( Time lhs, Time rhs ) { return lhs.tv < rhs.tv; }
     171        _Bool ?<=?( Time lhs, Time rhs ) { return lhs.tv <= rhs.tv; }
     172        _Bool ?>?( Time lhs, Time rhs ) { return lhs.tv > rhs.tv; }
     173        _Bool ?>=?( Time lhs, Time rhs ) { return lhs.tv >= rhs.tv; }
     174} // distribution
    168175
    169176char * yy_mm_dd( Time time, char * buf );
Note: See TracChangeset for help on using the changeset viewer.