Changeset 8eb2018 for src/libcfa/time


Ignore:
Timestamp:
Apr 1, 2018, 10:26:48 PM (7 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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.