Changeset 8eb2018


Ignore:
Timestamp:
Apr 1, 2018, 10:26:48 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
Children:
1031c7e, 9f652a1
Parents:
ce28c7b
Message:

cleanup, remove conversion of timeval/timespec to duration

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/time

    rce28c7b r8eb2018  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar 28 18:03:08 2018
    13 // Update Count     : 568
     12// Last Modified On : Sun Apr  1 20:03:16 2018
     13// Update Count     : 581
    1414//
    1515
     
    3131
    3232static inline void ?{}( timeval & t ) {}
    33 static inline void ?{}( timeval & t, time_t sec ) { t.tv_sec = sec; t.tv_usec = 0; }
    3433static inline void ?{}( timeval & t, time_t sec, suseconds_t usec ) { t.tv_sec = sec; t.tv_usec = usec; }
    35 static inline void ?{}( timeval & t, zero_t ) { t.tv_sec = 0; t.tv_usec = 0; }
     34static inline void ?{}( timeval & t, time_t sec ) { t{ sec, 0 }; }
     35static inline void ?{}( timeval & t, zero_t ) { t{ 0, 0 }; }
    3636static inline timeval ?=?( timeval & t, zero_t ) { return t{ 0 }; }
    3737static inline timeval ?+?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_usec + rhs.tv_usec }; }
     
    4444
    4545static inline void ?{}( timespec & t ) {}
    46 static inline void ?{}( timespec & t, time_t sec ) { t.tv_sec = sec; t.tv_nsec = 0; }
    4746static inline void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ) { t.tv_sec = sec; t.tv_nsec = nsec; }
    48 static inline void ?{}( timespec & t, zero_t ) { t.tv_sec = 0; t.tv_nsec = 0; }
     47static inline void ?{}( timespec & t, time_t sec ) { t{ sec, 0}; }
     48static inline void ?{}( timespec & t, zero_t ) { t{ 0, 0 }; }
    4949static inline timespec ?=?( timespec & t, zero_t ) { return t{ 0 }; }
    5050static inline timespec ?+?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_nsec + rhs.tv_nsec }; }
     
    7474static inline Duration ?=?( Duration & dur, zero_t ) { return dur{ 0 }; }
    7575
     76#if 0
    7677static inline void ?{}( Duration & dur, timeval t ) with( dur ) {
    7778        tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000;
     
    9192        return dur;
    9293} // ?=? timespec
    93 
    94 static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; }
     94#endif
     95
     96//static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; }
    9597
    9698static inline Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; }
     
    106108static inline Duration ?*=?( Duration & lhs, int64_t rhs ) { lhs = lhs * rhs; return lhs; }
    107109
     110static inline int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; }
    108111static inline Duration ?/?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv / rhs }; }
    109 static inline int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; }
    110112static inline Duration ?/=?( Duration & lhs, int64_t rhs ) { lhs = lhs / rhs; return lhs; }
    111113
     
    142144static inline Duration ?`d ( double  days  ) { return (Duration)@{ days * (24LL * 3600LL * TIMEGRAN) }; }
    143145static inline Duration ?`w ( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 3600LL * TIMEGRAN) }; }
    144 static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 3600LL * TIMEGRAN) }; }
     146//static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 3600LL * TIMEGRAN) }; }
    145147
    146148static inline int64_t ?`ns ( Duration dur ) { return dur.tv; }
     
    176178};
    177179
    178 void mktime( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec );
    179 
    180180static inline void ?{}( Time & t ) with( t ) {
    181181        tv = 0;
    182182} // Time
    183183
    184 static inline void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ) {
    185         mktime( time, year, month, day, hour, min, sec, nsec );
    186 } // Time
     184void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec );
    187185
    188186static inline void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec ) {
    189         mktime( time, year, month, day, hour, min, sec, 0 );
     187        time{ year, month, day, hour, min, sec, 0 };
    190188} // Time
    191189
    192190static inline void ?{}( Time & time, int year, int month, int day, int hour, int min ) {
    193         mktime( time, year, month, day, hour, min, 0, 0 );
     191        time{ year, month, day, hour, min, 0, 0 };
    194192} // Time
    195193
    196194static inline void ?{}( Time & time, int year, int month, int day, int hour ) {
    197         mktime( time, year, month, day, hour, 0, 0, 0 );
     195        time{ year, month, day, hour, 0, 0, 0 };
    198196} // Time
    199197
    200198static inline void ?{}( Time & time, int year, int month, int day ) {
    201         mktime( time, year, month, day, 0, 0, 0, 0 );
     199        time{ year, month, day, 0, 0, 0, 0 };
    202200} // Time
    203201
    204202static inline void ?{}( Time & time, int year, int month ) {
    205         mktime( time, year, month, 0, 0, 0, 0, 0 );
     203        time{ year, month, 0, 0, 0, 0, 0 };
    206204} // Time
    207205
    208206static inline void ?{}( Time & time, int year ) {
    209         mktime( time, year, 0, 0, 0, 0, 0, 0 );
     207        time{ year, 0, 0, 0, 0, 0, 0 };
    210208} // Time
    211209
     
    293291static inline void resetClock( Clock & clk, Duration adj ) with( clk ) {
    294292        clocktype = -1;
    295         Duration tz = (timeval){ timezone, 0 };
    296         offset = adj + tz;
     293        offset = adj + timezone`s;                                                      // timezone is (UTC - local time) in seconds
    297294} // resetClock
    298295
     
    308305        struct timespec res;
    309306        clock_getres( CLOCK_REALTIME_COARSE, &res );
    310         return (Duration){ res };
     307        return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    311308} // getRes
    312309
  • src/libcfa/time.c

    rce28c7b r8eb2018  
    1010// Created On       : Tue Mar 27 13:33:14 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 27 16:37:35 2018
    13 // Update Count     : 18
     12// Last Modified On : Sun Apr  1 17:30:08 2018
     13// Update Count     : 21
    1414//
    1515
     
    4949#endif // __CFA_DEBUG__
    5050
    51 void mktime( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ) with( time ) {
     51void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ) with( time ) {
    5252        tm tm;
    5353
     
    8181        } // if
    8282#endif // __CFA_DEBUG__
    83 } // mktime
     83} // ?{}
    8484
    8585char * yy_mm_dd( Time time, char * buf ) with( time ) {
  • src/tests/.expect/time.x64.txt

    rce28c7b r8eb2018  
    66
    77Fri Jan  2 00:00:00.01 1970
    8 Fri Jan  2 00:00:14.01 1970 0 Fri Jan  2 00:00:15.01001 1970 104414010000000
     8Fri Jan  2 00:00:14.01 1970 104414010000000
     9Fri Jan  2 00:00:14.01 1970 104414010000000
     100 Fri Jan  2 00:00:15.01001 1970 104414010000000
    911yy/mm/dd 70/01/02 mm/dd/yy 01/02/70 mm/dd/yy 01/02/70 dd/yy/mm 02/01/70
     12Wed Jul  4 00:00:01 2001 994219201000000000
    1013Wed Jul  4 00:00:01 2001 994219201000000000
    1114
  • src/tests/time.c

    rce28c7b r8eb2018  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 27 17:27:26 2018
    13 // Update Count     : 2
     12// Last Modified On : Sun Apr  1 21:49:51 2018
     13// Update Count     : 12
    1414//
    1515
     
    1818
    1919int main() {
    20         Duration d1 = 3`h, d2 = 2`s, d3 = 3.07`s, d4 = (timeval){ 12 }, d5 = (timespec){ 1, 10000 };
     20        Duration d1 = 3`h, d2 = 2`s, d3 = 3.07`s, d4 = 12`s, d5 = 1`s + 10_000`ns;
    2121        sout | d1 | d2 | d3 | d4 | d5 | endl;
    2222        int i;
     
    3434        sout | t | endl;
    3535        t = t + d1;
    36         sout | t | t - t | t + d5 | t.tv | endl;
     36        sout | t | t.tv | endl;
     37        Time t1 = (timespec){ 104_414, 10_000_000 };
     38        sout | t1 | t1.tv | endl;
     39        sout | t - t  | t + d5 | t.tv | endl;
    3740        char buf[16];
    3841        sout | "yy/mm/dd" | [t, buf]`ymd;                                       // shared buf => separate calls
     
    4144        sout | "mm/dd/yy" | buf;
    4245        sout | "dd/yy/mm" | [t, buf]`dmy | endl;
    43         Time c = { 2001, 7, 4, 0, 0, 1, 0 };
    44         sout | c | c.tv | endl;
     46        Time t2 = { 2001, 7, 4, 0, 0, 1, 0 }, t3 = (timeval){ 994_219_201 };
     47        sout | t2 | t2.tv | endl | t3 | t3.tv | endl;
    4548        sout | endl;
    4649
Note: See TracChangeset for help on using the changeset viewer.