Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/clock

    rbbe1a87 r10a97adb  
    1010// Created On       : Thu Apr 12 14:36:06 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul  2 21:40:01 2018
    13 // Update Count     : 7
     12// Last Modified On : Thu Apr 12 16:53:31 2018
     13// Update Count     : 3
    1414//
    1515
     
    3434};
    3535
    36 static inline {
    37         void resetClock( Clock & clk ) with( clk ) {
    38                 clocktype = CLOCK_REALTIME_COARSE;
    39         } // Clock::resetClock
     36static inline void resetClock( Clock & clk ) with( clk ) {
     37        clocktype = CLOCK_REALTIME_COARSE;
     38} // Clock::resetClock
    4039
    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
     40static 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
    4544
    46         void ?{}( Clock & clk ) { resetClock( clk ); }
    47         void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }
     45static inline void ?{}( Clock & clk ) { resetClock( clk ); }
     46static inline void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }
    4847
    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
     48static inline Duration getRes() {
     49        struct timespec res;
     50        clock_getres( CLOCK_REALTIME_COARSE, &res );
     51        return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
     52} // getRes
    5453
    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
     54static inline Time getTimeNsec() {                                              // with nanoseconds
     55        timespec curr;
     56        clock_gettime( CLOCK_REALTIME_COARSE, &curr );
     57        return (Time){ curr };
     58} // getTime
    6059
    61         Time getTimeNsec() {                                                            // with nanoseconds
    62                 timespec curr;
    63                 clock_gettime( CLOCK_REALTIME, &curr );
    64                 return (Time){ curr };
    65         } // getTime
     60static inline Time getTime() {                                                  // without nanoseconds
     61        timespec curr;
     62        clock_gettime( CLOCK_REALTIME_COARSE, &curr );
     63        curr.tv_nsec = 0;
     64        return (Time){ curr };
     65} // getTime
    6666
    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
     67static inline Time getTime( Clock & clk ) with( clk ) {
     68        return getTime() + offset;
     69} // getTime
    7370
    74         Time getTime( Clock & clk ) with( clk ) {
    75                 return getTime() + offset;
    76         } // getTime
     71static inline Time ?()( Clock & clk ) with( clk ) {             // alternative syntax
     72        return getTime() + offset;
     73} // getTime
    7774
    78         Time ?()( Clock & clk ) with( clk ) {                           // alternative syntax
    79                 return getTime() + offset;
    80         } // getTime
     75static inline timeval getTime( Clock & clk ) {
     76        return (timeval){ clk() };
     77} // getTime
    8178
    82         timeval getTime( Clock & clk ) {
    83                 return (timeval){ clk() };
    84         } // getTime
    85 
    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
     79static inline tm getTime( Clock & clk ) with( clk ) {
     80        tm ret;
     81        localtime_r( getTime( clk ).tv_sec, &ret );
     82        return ret;
     83} // getTime
    9284
    9385// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.