Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/clock.hfa

    r4aa495f r6645cda  
    1010// Created On       : Thu Apr 12 14:36:06 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Apr 18 08:12:16 2021
    13 // Update Count     : 28
     12// Last Modified On : Wed Apr 14 17:48:25 2021
     13// Update Count     : 20
    1414//
    1515
     
    2727//######################### Clock #########################
    2828
    29 struct Clock {                                                                                  // virtual clock
    30         // private
    31         Duration offset;                                                                        // offset from computer real-time
     29struct Clock {                                                                                  // private
     30        Duration offset;                                                                        // for virtual clock: contains offset from real-time
    3231};
    3332
    3433static inline {
    35         void reset( Clock & clk, Duration adj ) with( clk ) { // change offset
     34        void reset( Clock & clk, Duration adj ) with( clk ) {
    3635                offset = adj + __timezone`s;                                    // timezone (global) is (UTC - local time) in seconds
    3736        } // reset
    3837
    39         void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } // create no offset
    40         void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } // create with offset
     38        void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); }
     39        void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); }
    4140
    4241        // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in
    4342        // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3)
    4443        // and NTP (daylight saving (Fall back).
    45         Duration resolutionHi() {                                                       // clock resolution in nanoseconds (fine)
     44        Duration resolutionNsec() {
    4645                struct timespec res;
    4746                clock_getres( CLOCK_REALTIME, &res );
    4847                return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;
    49         } // resolutionHi
     48        } // resolutionNsec
    5049
    51         Duration resolution() {                                                         // clock resolution without nanoseconds (coarse)
     50        Duration resolution() {
    5251                struct timespec res;
    5352                clock_getres( CLOCK_REALTIME_COARSE, &res );
     
    5554        } // resolution
    5655
    57         Time timeHiRes() {                                                                      // real time with nanoseconds
     56        Time timeNsec() {                                                                       // with nanoseconds
    5857                timespec curr;
    5958                clock_gettime( CLOCK_REALTIME, &curr );
    6059                return (Time){ curr };
    61         } // timeHiRes
     60        } // timeNsec
    6261
    63         Time time() {                                                                           // real time without nanoseconds
     62        Time time() {                                                                           // without nanoseconds
    6463                timespec curr;
    6564                clock_gettime( CLOCK_REALTIME_COARSE, &curr );
     
    6867        } // time
    6968
    70         Time time( Clock & clk ) with( clk ) {                          // real time for given clock
     69        Time time( Clock & clk ) with( clk ) {
    7170                return time() + offset;
    7271        } // time
     
    7675        } // ?()
    7776
    78         timeval time( Clock & clk ) {                                           // convert to C time format
     77        timeval time( Clock & clk ) {
    7978                return (timeval){ clk() };
    8079        } // time
     
    8988        // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is
    9089        // relative and cannot be converted to real-time (wall-clock) time.
    91         Duration processor() {                                                          // non-monotonic duration of kernel thread
     90        Duration processor() {
    9291                timespec ts;
    9392                clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts );
     
    9897        // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned
    9998        // because the value is relative and cannot be converted to real-time (wall-clock) time.
    100         Duration program() {                                                            // non-monotonic duration of program CPU
     99        Duration program() {
    101100                timespec ts;
    102101                clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts );
     
    104103        } // program
    105104
    106         // Monotonic duration from machine boot and including system suspension. This watch is unaffected by discontinuous
    107         // jumps resulting from manual changes of the clock, and incremental adjustments performed by adjtime(3) and NTP
    108         // (Fall back). A duration is returned because the value is relative and cannot be converted to real-time
    109         // (wall-clock) time.
    110         Duration boot() {                                                                       // monotonic duration since computer boot
     105        // Monotonic stopwatch starting at machine boot and includes system suspension. This watch is unaffected by
     106        // discontinuous jumps resulting from manual changes of the clock, and incremental adjustments performed by
     107        // adjtime(3) and NTP (Fall back). A duration is returned because the value is relative and cannot be converted to
     108        // real-time (wall-clock) time.
     109        Duration boot() {
    111110                timespec ts;
    112111                clock_gettime( CLOCK_BOOTTIME, &ts );
Note: See TracChangeset for help on using the changeset viewer.