Changes in libcfa/src/clock.hfa [4aa495f:6645cda]
- File:
-
- 1 edited
-
libcfa/src/clock.hfa (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/clock.hfa
r4aa495f r6645cda 10 10 // Created On : Thu Apr 12 14:36:06 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Apr 18 08:12:16202113 // Update Count : 2 812 // Last Modified On : Wed Apr 14 17:48:25 2021 13 // Update Count : 20 14 14 // 15 15 … … 27 27 //######################### Clock ######################### 28 28 29 struct Clock { // virtual clock 30 // private 31 Duration offset; // offset from computer real-time 29 struct Clock { // private 30 Duration offset; // for virtual clock: contains offset from real-time 32 31 }; 33 32 34 33 static inline { 35 void reset( Clock & clk, Duration adj ) with( clk ) { // change offset34 void reset( Clock & clk, Duration adj ) with( clk ) { 36 35 offset = adj + __timezone`s; // timezone (global) is (UTC - local time) in seconds 37 36 } // reset 38 37 39 void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } // create no offset40 void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } // create with offset38 void ?{}( Clock & clk ) { reset( clk, (Duration){ 0 } ); } 39 void ?{}( Clock & clk, Duration adj ) { reset( clk, adj ); } 41 40 42 41 // System-wide clock that measures real, i.e., wall-clock) time. This clock is affected by discontinuous jumps in 43 42 // the system time. For example, manual changes of the clock, and incremental adjustments performed by adjtime(3) 44 43 // and NTP (daylight saving (Fall back). 45 Duration resolution Hi() { // clock resolution in nanoseconds (fine)44 Duration resolutionNsec() { 46 45 struct timespec res; 47 46 clock_getres( CLOCK_REALTIME, &res ); 48 47 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 49 } // resolution Hi48 } // resolutionNsec 50 49 51 Duration resolution() { // clock resolution without nanoseconds (coarse)50 Duration resolution() { 52 51 struct timespec res; 53 52 clock_getres( CLOCK_REALTIME_COARSE, &res ); … … 55 54 } // resolution 56 55 57 Time time HiRes() { // real timewith nanoseconds56 Time timeNsec() { // with nanoseconds 58 57 timespec curr; 59 58 clock_gettime( CLOCK_REALTIME, &curr ); 60 59 return (Time){ curr }; 61 } // time HiRes60 } // timeNsec 62 61 63 Time time() { // real timewithout nanoseconds62 Time time() { // without nanoseconds 64 63 timespec curr; 65 64 clock_gettime( CLOCK_REALTIME_COARSE, &curr ); … … 68 67 } // time 69 68 70 Time time( Clock & clk ) with( clk ) { // real time for given clock69 Time time( Clock & clk ) with( clk ) { 71 70 return time() + offset; 72 71 } // time … … 76 75 } // ?() 77 76 78 timeval time( Clock & clk ) { // convert to C time format77 timeval time( Clock & clk ) { 79 78 return (timeval){ clk() }; 80 79 } // time … … 89 88 // discontinuous jumps when the OS is not running the kernal thread. A duration is returned because the value is 90 89 // relative and cannot be converted to real-time (wall-clock) time. 91 Duration processor() { // non-monotonic duration of kernel thread90 Duration processor() { 92 91 timespec ts; 93 92 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); … … 98 97 // watch is affected by discontinuous jumps when the OS is not running the kernel threads. A duration is returned 99 98 // because the value is relative and cannot be converted to real-time (wall-clock) time. 100 Duration program() { // non-monotonic duration of program CPU99 Duration program() { 101 100 timespec ts; 102 101 clock_gettime( CLOCK_PROCESS_CPUTIME_ID, &ts ); … … 104 103 } // program 105 104 106 // Monotonic duration from machine boot and including system suspension. This watch is unaffected by discontinuous107 // jumps resulting from manual changes of the clock, and incremental adjustments performed by adjtime(3) and NTP108 // (Fall back). A duration is returned because the value is relative and cannot be converted to real-time109 // (wall-clock) time.110 Duration boot() { // monotonic duration since computer boot105 // 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() { 111 110 timespec ts; 112 111 clock_gettime( CLOCK_BOOTTIME, &ts );
Note:
See TracChangeset
for help on using the changeset viewer.