Changeset 273cde6 for src/libcfa/time
- Timestamp:
- Mar 30, 2018, 7:22:35 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, 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:
- 94ddede
- Parents:
- b10affd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/time
rb10affd r273cde6 10 10 // Created On : Wed Mar 14 23:18:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Mar 27 16:37:37201813 // Update Count : 56 412 // Last Modified On : Wed Mar 28 18:03:08 2018 13 // Update Count : 568 14 14 // 15 15 … … 25 25 #include <iostream> // istype/ostype 26 26 27 enum { TIMEGRAN = 1_000_000_000L };// nanosecond granularity, except for timeval27 enum { TIMEGRAN = 1_000_000_000LL }; // nanosecond granularity, except for timeval 28 28 29 29 … … 131 131 132 132 static inline Duration ?`ns( int64_t nsec ) { return (Duration)@{ nsec }; } 133 static inline Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000L ) }; }134 static inline Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000L ) }; }133 static inline Duration ?`us( int64_t usec ) { return (Duration)@{ usec * (TIMEGRAN / 1_000_000LL) }; } 134 static inline Duration ?`ms( int64_t msec ) { return (Duration)@{ msec * (TIMEGRAN / 1_000LL) }; } 135 135 static inline Duration ?`s ( int64_t sec ) { return (Duration)@{ sec * TIMEGRAN }; } 136 136 static inline Duration ?`s ( double sec ) { return (Duration)@{ sec * TIMEGRAN }; } 137 static inline Duration ?`m ( int64_t min ) { return (Duration)@{ min * (60L * TIMEGRAN) }; }138 static inline Duration ?`m ( double min ) { return (Duration)@{ min * (60L * TIMEGRAN) }; }139 static inline Duration ?`h ( int64_t hours ) { return (Duration)@{ hours * (3600L * TIMEGRAN) }; }140 static inline Duration ?`h ( double hours ) { return (Duration)@{ hours * (3600L * TIMEGRAN) }; }141 static inline Duration ?`d ( int64_t days ) { return (Duration)@{ days * (24L * 3600L * TIMEGRAN) }; }142 static inline Duration ?`d ( double days ) { return (Duration)@{ days * (24L * 3600L * TIMEGRAN) }; }143 static inline Duration ?`w ( int64_t weeks ) { return (Duration)@{ weeks * (7L * 24L * 3600L * TIMEGRAN) }; }144 static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14L * 24L * 3600L * TIMEGRAN) }; }137 static inline Duration ?`m ( int64_t min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 138 static inline Duration ?`m ( double min ) { return (Duration)@{ min * (60LL * TIMEGRAN) }; } 139 static inline Duration ?`h ( int64_t hours ) { return (Duration)@{ hours * (3600LL * TIMEGRAN) }; } 140 static inline Duration ?`h ( double hours ) { return (Duration)@{ hours * (3600LL * TIMEGRAN) }; } 141 static inline Duration ?`d ( int64_t days ) { return (Duration)@{ days * (24LL * 3600LL * TIMEGRAN) }; } 142 static inline Duration ?`d ( double days ) { return (Duration)@{ days * (24LL * 3600LL * TIMEGRAN) }; } 143 static inline Duration ?`w ( int64_t weeks ) { return (Duration)@{ weeks * (7LL * 24LL * 3600LL * TIMEGRAN) }; } 144 static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 3600LL * TIMEGRAN) }; } 145 145 146 146 static inline int64_t ?`ns ( Duration dur ) { return dur.tv; } 147 static inline int64_t ?`us ( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000_000L ); }148 static inline int64_t ?`ms ( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000L ); }147 static inline int64_t ?`us ( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000_000LL); } 148 static inline int64_t ?`ms ( Duration dur ) { return dur.tv / (TIMEGRAN / 1_000LL); } 149 149 static inline int64_t ?`s ( Duration dur ) { return dur.tv / TIMEGRAN; } 150 static inline int64_t ?`m ( Duration dur ) { return dur.tv / (60L * TIMEGRAN); }151 static inline int64_t ?`h ( Duration dur ) { return dur.tv / (3600L * TIMEGRAN); }152 static inline int64_t ?`d ( Duration dur ) { return dur.tv / (24L * 3600L * TIMEGRAN); }153 static inline int64_t ?`w ( Duration dur ) { return dur.tv / (7L * 24L * 3600L * TIMEGRAN); }154 static inline int64_t ?`f ( Duration dur ) { return dur.tv / (14L * 24L * 3600L * TIMEGRAN); }150 static inline int64_t ?`m ( Duration dur ) { return dur.tv / (60LL * TIMEGRAN); } 151 static inline int64_t ?`h ( Duration dur ) { return dur.tv / (3600LL * TIMEGRAN); } 152 static inline int64_t ?`d ( Duration dur ) { return dur.tv / (24LL * 3600LL * TIMEGRAN); } 153 static inline int64_t ?`w ( Duration dur ) { return dur.tv / (7LL * 24LL * 3600LL * TIMEGRAN); } 154 static inline int64_t ?`f ( Duration dur ) { return dur.tv / (14LL * 24LL * 3600LL * TIMEGRAN); } 155 155 156 156 //------------------------- timeval (cont) ------------------------- … … 158 158 static inline void ?{}( timeval & t, Duration dur ) with( dur ) { 159 159 t.tv_sec = tv / TIMEGRAN; // seconds 160 t.tv_usec = tv % TIMEGRAN / (TIMEGRAN / 1_000_000L ); // microseconds160 t.tv_usec = tv % TIMEGRAN / (TIMEGRAN / 1_000_000LL); // microseconds 161 161 } // ?{} 162 162 … … 222 222 223 223 static inline Time ?=?( Time & time, timeval t ) with( time ) { 224 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000L );224 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * (TIMEGRAN / 1_000_000LL); 225 225 return time; 226 226 } // ?=? … … 230 230 return time; 231 231 } // ?=? 232 233 static inline void ?{}( timeval & t, Time time ) with( time ) {234 t.tv_sec = tv / TIMEGRAN; // seconds235 t.tv_usec = tv % TIMEGRAN / ( TIMEGRAN / 1_000_000L ); // microseconds236 } // ?{}237 238 static inline void ?{}( timespec & t, Time time ) with( time ) {239 t.tv_sec = tv / TIMEGRAN; // seconds240 t.tv_nsec = tv % TIMEGRAN; // nanoseconds241 } // ?{}242 232 243 233 static inline Time ?+?( Time & lhs, Duration rhs ) { return (Time)@{ lhs.tv + rhs.tv }; } … … 274 264 forall( dtype ostype | ostream( ostype ) ) ostype & ?|?( ostype & os, Time time ); 275 265 266 //------------------------- timeval (cont) ------------------------- 267 268 static inline void ?{}( timeval & t, Time time ) with( t, time ) { 269 tv_sec = tv / TIMEGRAN; // seconds 270 tv_usec = tv % TIMEGRAN / (TIMEGRAN / 1_000_000LL); // microseconds 271 } // ?{} 272 273 //------------------------- timespec (cont) ------------------------- 274 275 static inline void ?{}( timespec & t, Time time ) with( t, time ) { 276 tv_sec = tv / TIMEGRAN; // seconds 277 tv_nsec = tv % TIMEGRAN; // nanoseconds 278 } // ?{} 279 276 280 277 281 //######################### Clock #########################
Note: See TracChangeset
for help on using the changeset viewer.