Changeset 8eb2018 for src/libcfa/time
- Timestamp:
- Apr 1, 2018, 10:26:48 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:
- 1031c7e, 9f652a1
- Parents:
- ce28c7b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/time
rce28c7b r8eb2018 10 10 // Created On : Wed Mar 14 23:18:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Mar 28 18:03:08201813 // Update Count : 5 6812 // Last Modified On : Sun Apr 1 20:03:16 2018 13 // Update Count : 581 14 14 // 15 15 … … 31 31 32 32 static inline void ?{}( timeval & t ) {} 33 static inline void ?{}( timeval & t, time_t sec ) { t.tv_sec = sec; t.tv_usec = 0; }34 33 static inline void ?{}( timeval & t, time_t sec, suseconds_t usec ) { t.tv_sec = sec; t.tv_usec = usec; } 35 static inline void ?{}( timeval & t, zero_t ) { t.tv_sec = 0; t.tv_usec = 0; } 34 static inline void ?{}( timeval & t, time_t sec ) { t{ sec, 0 }; } 35 static inline void ?{}( timeval & t, zero_t ) { t{ 0, 0 }; } 36 36 static inline timeval ?=?( timeval & t, zero_t ) { return t{ 0 }; } 37 37 static inline timeval ?+?( timeval & lhs, timeval rhs ) { return (timeval)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_usec + rhs.tv_usec }; } … … 44 44 45 45 static inline void ?{}( timespec & t ) {} 46 static inline void ?{}( timespec & t, time_t sec ) { t.tv_sec = sec; t.tv_nsec = 0; }47 46 static inline void ?{}( timespec & t, time_t sec, __syscall_slong_t nsec ) { t.tv_sec = sec; t.tv_nsec = nsec; } 48 static inline void ?{}( timespec & t, zero_t ) { t.tv_sec = 0; t.tv_nsec = 0; } 47 static inline void ?{}( timespec & t, time_t sec ) { t{ sec, 0}; } 48 static inline void ?{}( timespec & t, zero_t ) { t{ 0, 0 }; } 49 49 static inline timespec ?=?( timespec & t, zero_t ) { return t{ 0 }; } 50 50 static inline timespec ?+?( timespec & lhs, timespec rhs ) { return (timespec)@{ lhs.tv_sec + rhs.tv_sec, lhs.tv_nsec + rhs.tv_nsec }; } … … 74 74 static inline Duration ?=?( Duration & dur, zero_t ) { return dur{ 0 }; } 75 75 76 #if 0 76 77 static inline void ?{}( Duration & dur, timeval t ) with( dur ) { 77 78 tv = (int64_t)t.tv_sec * TIMEGRAN + t.tv_usec * 1000; … … 91 92 return dur; 92 93 } // ?=? timespec 93 94 static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; } 94 #endif 95 96 //static inline int64_t nsecs( Duration dur ) with( dur ) { return tv; } 95 97 96 98 static inline Duration +?( Duration rhs ) with( rhs ) { return (Duration)@{ +tv }; } … … 106 108 static inline Duration ?*=?( Duration & lhs, int64_t rhs ) { lhs = lhs * rhs; return lhs; } 107 109 110 static inline int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; } 108 111 static inline Duration ?/?( Duration lhs, int64_t rhs ) { return (Duration)@{ lhs.tv / rhs }; } 109 static inline int64_t ?/?( Duration lhs, Duration rhs ) { return lhs.tv / rhs.tv; }110 112 static inline Duration ?/=?( Duration & lhs, int64_t rhs ) { lhs = lhs / rhs; return lhs; } 111 113 … … 142 144 static inline Duration ?`d ( double days ) { return (Duration)@{ days * (24LL * 3600LL * TIMEGRAN) }; } 143 145 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) }; }146 //static inline Duration ?`f ( int64_t fortnight ) { return (Duration)@{ fortnight * (14LL * 24LL * 3600LL * TIMEGRAN) }; } 145 147 146 148 static inline int64_t ?`ns ( Duration dur ) { return dur.tv; } … … 176 178 }; 177 179 178 void mktime( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec );179 180 180 static inline void ?{}( Time & t ) with( t ) { 181 181 tv = 0; 182 182 } // Time 183 183 184 static inline void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ) { 185 mktime( time, year, month, day, hour, min, sec, nsec ); 186 } // Time 184 void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec, int nsec ); 187 185 188 186 static inline void ?{}( Time & time, int year, int month, int day, int hour, int min, int sec ) { 189 mktime( time, year, month, day, hour, min, sec, 0 );187 time{ year, month, day, hour, min, sec, 0 }; 190 188 } // Time 191 189 192 190 static inline void ?{}( Time & time, int year, int month, int day, int hour, int min ) { 193 mktime( time, year, month, day, hour, min, 0, 0 );191 time{ year, month, day, hour, min, 0, 0 }; 194 192 } // Time 195 193 196 194 static inline void ?{}( Time & time, int year, int month, int day, int hour ) { 197 mktime( time, year, month, day, hour, 0, 0, 0 );195 time{ year, month, day, hour, 0, 0, 0 }; 198 196 } // Time 199 197 200 198 static inline void ?{}( Time & time, int year, int month, int day ) { 201 mktime( time, year, month, day, 0, 0, 0, 0 );199 time{ year, month, day, 0, 0, 0, 0 }; 202 200 } // Time 203 201 204 202 static inline void ?{}( Time & time, int year, int month ) { 205 mktime( time, year, month, 0, 0, 0, 0, 0 );203 time{ year, month, 0, 0, 0, 0, 0 }; 206 204 } // Time 207 205 208 206 static inline void ?{}( Time & time, int year ) { 209 mktime( time, year, 0, 0, 0, 0, 0, 0 );207 time{ year, 0, 0, 0, 0, 0, 0 }; 210 208 } // Time 211 209 … … 293 291 static inline void resetClock( Clock & clk, Duration adj ) with( clk ) { 294 292 clocktype = -1; 295 Duration tz = (timeval){ timezone, 0 }; 296 offset = adj + tz; 293 offset = adj + timezone`s; // timezone is (UTC - local time) in seconds 297 294 } // resetClock 298 295 … … 308 305 struct timespec res; 309 306 clock_getres( CLOCK_REALTIME_COARSE, &res ); 310 return ( Duration){ res };307 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns; 311 308 } // getRes 312 309
Note: See TracChangeset
for help on using the changeset viewer.