Changeset bc03be3 for src/libcfa/time
- Timestamp:
- Apr 4, 2018, 9:50:23 PM (5 years ago)
- Branches:
- ADT, 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, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 643c6b9
- Parents:
- bb37870
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/time
rbb37870 rbc03be3 10 10 // Created On : Wed Mar 14 23:18:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 3 08:46:08 201813 // Update Count : 5 8512 // Last Modified On : Wed Apr 4 16:28:48 2018 13 // Update Count : 595 14 14 // 15 15 … … 63 63 static inline tm * localtime_r( time_t tp, tm * result ) { return localtime_r( &tp, result ); } 64 64 65 65 66 //######################### Duration ######################### 66 67 67 68 struct Duration { 68 int64_t tv; 69 }; 69 int64_t tv; // nanoseconds 70 }; // Duration 70 71 71 72 static inline void ?{}( Duration & dur ) with( dur ) { tv = 0; } … … 92 93 return dur; 93 94 } // ?=? timespec 95 96 //------------------------- timeval (cont) ------------------------- 97 98 static 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 105 static 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 110 static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; } 94 111 #endif 95 96 //static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; }97 112 98 113 static inline Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; } … … 129 144 static inline _Bool ?>=?( Duration lhs, zero_t ) { return lhs.tv >= 0; } 130 145 131 static inline Duration abs( Duration lhs ) { return lhs.tv >= 0 ? lhs : -lhs; }146 static inline Duration abs( Duration rhs ) { return rhs.tv >= 0 ? rhs : -rhs; } 132 147 133 148 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Duration dur ); 134 149 135 static inline Duration ?`ns( int64_t nsec 136 static inline Duration ?`us( int64_t usec 137 static inline Duration ?`ms( int64_t msec 138 static inline Duration ?`s ( int64_t sec 139 static inline Duration ?`s ( double sec) { return (Duration)@{ sec * TIMEGRAN }; }140 static inline Duration ?`m ( int64_t min 141 static inline Duration ?`m ( double min) { return (Duration)@{ min * (60LL * TIMEGRAN) }; }150 static inline Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; } 151 static inline Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; } 152 static inline Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; } 153 static inline Duration ?`s ( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; } 154 static inline Duration ?`s ( double sec ) { return (Duration)@{ sec * TIMEGRAN }; } 155 static inline Duration ?`m ( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 156 static inline Duration ?`m ( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 142 157 static inline Duration ?`h ( int64_t hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; } 143 static inline Duration ?`h ( double 144 static inline Duration ?`d ( int64_t days 145 static inline Duration ?`d ( double days) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; }158 static inline Duration ?`h ( double hours ) { return (Duration)@{ hours * (60LL * 60LL * TIMEGRAN) }; } 159 static inline Duration ?`d ( int64_t days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; } 160 static inline Duration ?`d ( double days ) { return (Duration)@{ days * (24LL * 60LL * 60LL * TIMEGRAN) }; } 146 161 static inline Duration ?`w ( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 147 static inline Duration ?`w ( double 162 static inline Duration ?`w ( double weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 148 163 //static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } 149 164 //static inline Duration ?`f ( double fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 60LL * 60LL * TIMEGRAN) }; } … … 159 174 static inline int64_t ?`f ( Duration dur ) { return dur.tv / (14LL * 24LL * 60LL * 60LL * TIMEGRAN); } 160 175 161 //------------------------- timeval (cont) -------------------------162 163 static inline void ?{}( timeval & t, Duration dur ) with( dur ) {164 t.tv_sec = tv / TIMEGRAN; // seconds165 t.tv_usec = tv % TIMEGRAN / (TIMEGRAN / 1_000_000LL); // microseconds166 } // ?{}167 168 //------------------------- timespec (cont) -------------------------169 170 static inline void ?{}( timespec & t, Duration dur ) with( dur ) {171 t.tv_sec = tv / TIMEGRAN; // seconds172 t.tv_nsec = tv % TIMEGRAN; // nanoseconds173 } // Timespec174 175 176 176 177 //######################### Time ######################### 177 178 178 179 179 struct Time { 180 uint64_t tv; 180 uint64_t tv; // nanoseconds since UNIX epoch 181 181 }; 182 182 … … 211 211 } // Time 212 212 213 static inline void ?{}( Time & t, zero_t ) { t.tv = 0; } 214 static inline Time ?=?( Time & t, zero_t ) { return t{ 0 }; } 215 213 216 static inline void ?{}( Time & time, timeval t ) with( time ) { 214 217 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; 215 218 } // Time 216 217 static inline void ?{}( Time & time, timespec t ) with( time ) {218 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec;219 } // Time220 221 static inline void ?{}( Time & t, zero_t ) { t.tv = 0; }222 static inline Time ?=?( Time & t, zero_t ) { return t{ 0 }; }223 219 224 220 static inline Time ?=?( Time & time, timeval t ) with( time ) { … … 226 222 return time; 227 223 } // ?=? 224 225 static inline void ?{}( Time & time, timespec t ) with( time ) { 226 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_nsec; 227 } // Time 228 228 229 229 static inline Time ?=?( Time & time, timespec t ) with( time ) { … … 282 282 //######################### Clock ######################### 283 283 284 285 284 struct Clock { 286 285 Duration offset; // for virtual clock: contains offset from real-time
Note: See TracChangeset
for help on using the changeset viewer.