Changeset bc03be3


Ignore:
Timestamp:
Apr 4, 2018, 9:50:23 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, 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, with_gc
Children:
643c6b9
Parents:
bb37870
Message:

formatting, remove convert of timeval/timespec to Duration, adjust preemption alarm

Location:
src/libcfa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/alarm.c

    rbb37870 rbc03be3  
    1010// Created On       : Fri Jun 2 11:31:25 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 27 14:12:11 2018
    13 // Update Count     : 41
     12// Last Modified On : Wed Apr  4 16:47:29 2018
     13// Update Count     : 49
    1414//
    1515
     
    2828
    2929static inline void ?{}( itimerval & this, Duration alarm ) with( this ) {
    30         it_value   { alarm };                                                           // seconds, microseconds
    31         it_interval{ 0 };
     30        // itimerval.it_value is a duration but uses time data-structure timeval.
     31        it_value{ alarm`s, alarm`us };                                          // seconds, microseconds
     32        it_interval{ 0 };                                                                       // 0 seconds, 0 microseconds
    3233}
    3334
  • src/libcfa/time

    rbb37870 rbc03be3  
    1010// Created On       : Wed Mar 14 23:18:57 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Apr  3 08:46:08 2018
    13 // Update Count     : 585
     12// Last Modified On : Wed Apr  4 16:28:48 2018
     13// Update Count     : 595
    1414//
    1515
     
    6363static inline tm * localtime_r( time_t tp, tm * result ) { return localtime_r( &tp, result ); }
    6464
     65
    6566//######################### Duration #########################
    6667
    6768struct Duration {
    68         int64_t tv;
    69 };
     69        int64_t tv;                                                                                     // nanoseconds
     70}; // Duration
    7071
    7172static inline void ?{}( Duration & dur ) with( dur ) { tv = 0; }
     
    9293        return dur;
    9394} // ?=? timespec
     95
     96//------------------------- timeval (cont) -------------------------
     97
     98static inline void ?{}( timeval & t, Duration dur ) with( dur ) {
     99        t.tv_sec = tv / TIMEGRAN;                                                       // seconds
     100        t.tv_usec = tv % TIMEGRAN / (TIMEGRAN / 1_000_000LL); // microseconds
     101} // ?{}
     102
     103//------------------------- timespec (cont) -------------------------
     104
     105static inline void ?{}( timespec & t, Duration dur ) with( dur ) {
     106        t.tv_sec = tv / TIMEGRAN;                                                       // seconds
     107        t.tv_nsec = tv % TIMEGRAN;                                                      // nanoseconds
     108} // Timespec
     109
     110static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; }
    94111#endif
    95 
    96 //static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; }
    97112
    98113static inline Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; }
     
    129144static inline _Bool ?>=?( Duration lhs, zero_t ) { return lhs.tv >= 0; }
    130145
    131 static inline Duration abs( Duration lhs ) { return lhs.tv >= 0 ? lhs : -lhs; }
     146static inline Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; }
    132147
    133148forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur );
    134149
    135 static inline Duration ?`ns( int64_t nsec  ) { return (Duration)@{ nsec }; }
    136 static inline Duration ?`us( int64_t usec  ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; }
    137 static inline Duration ?`ms( int64_t msec  ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; }
    138 static inline Duration ?`s ( int64_t sec   ) { return (Duration)@{ sec * TIMEGRAN }; }
    139 static inline Duration ?`s ( double  sec  ) { return (Duration)@{ sec * TIMEGRAN }; }
    140 static inline Duration ?`m ( int64_t min   ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
    141 static inline Duration ?`m ( double  min  ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
     150static inline Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; }
     151static inline Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; }
     152static inline Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; }
     153static inline Duration ?`s ( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; }
     154static inline Duration ?`s ( double sec ) { return (Duration)@{ sec * TIMEGRAN }; }
     155static inline Duration ?`m ( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
     156static inline Duration ?`m ( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }
    142157static inline Duration ?`h ( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
    143 static inline Duration ?`h ( double  hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
    144 static inline Duration ?`d ( int64_t days  ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
    145 static inline Duration ?`d ( double  days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
     158static inline Duration ?`h ( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; }
     159static inline Duration ?`d ( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
     160static inline Duration ?`d ( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }
    146161static inline Duration ?`w ( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    147 static inline Duration ?`w ( double  weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
     162static inline Duration ?`w ( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    148163//static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
    149164//static inline Duration ?`f ( double  fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 60LL * 60LL * TIMEGRAN) }; }
     
    159174static inline int64_t ?`f  ( Duration dur ) { return dur.tv / (14LL * 24LL * 60LL * 60LL * TIMEGRAN); }
    160175
    161 //------------------------- timeval (cont) -------------------------
    162 
    163 static inline void ?{}( timeval & t, Duration dur ) with( dur ) {
    164         t.tv_sec = tv / TIMEGRAN;                                                       // seconds
    165         t.tv_usec = tv % TIMEGRAN / (TIMEGRAN / 1_000_000LL); // microseconds
    166 } // ?{}
    167 
    168 //------------------------- timespec (cont) -------------------------
    169 
    170 static inline void ?{}( timespec & t, Duration dur ) with( dur ) {
    171         t.tv_sec = tv / TIMEGRAN;                                                       // seconds
    172         t.tv_nsec = tv % TIMEGRAN;                                                      // nanoseconds
    173 } // Timespec
    174 
    175176
    176177//######################### Time #########################
    177178
    178 
    179179struct Time {
    180         uint64_t tv;
     180        uint64_t tv;                                                                            // nanoseconds since UNIX epoch
    181181};
    182182
     
    211211} // Time
    212212
     213static inline void ?{}( Time & t, zero_t ) { t.tv = 0; }
     214static inline Time ?=?( Time & t, zero_t ) { return t{ 0 }; }
     215
    213216static inline void ?{}( Time & time, timeval t ) with( time ) {
    214217        tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000;
    215218} // Time
    216 
    217 static inline void ?{}( Time & time, timespec t ) with( time ) {
    218         tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;
    219 } // Time
    220 
    221 static inline void ?{}( Time & t, zero_t ) { t.tv = 0; }
    222 static inline Time ?=?( Time & t, zero_t ) { return t{ 0 }; }
    223219
    224220static inline Time ?=?( Time & time, timeval t ) with( time ) {
     
    226222        return time;
    227223} // ?=?
     224
     225static inline void ?{}( Time & time, timespec t ) with( time ) {
     226        tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;
     227} // Time
    228228
    229229static inline Time ?=?( Time & time, timespec t ) with( time ) {
     
    282282//######################### Clock #########################
    283283
    284 
    285284struct Clock {
    286285        Duration offset;                                                                        // for virtual clock: contains offset from real-time
Note: See TracChangeset for help on using the changeset viewer.