Changeset 4834563
- Timestamp:
- Jan 6, 2020, 2:13:42 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 90cb6f7
- Parents:
- e0c235c
- Location:
- libcfa/src
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/startup.cfa
re0c235c r4834563 10 10 // Created On : Tue Jul 24 16:21:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Nov 30 07:07:56201913 // Update Count : 1312 // Last Modified On : Fri Dec 13 13:16:45 2019 13 // Update Count : 29 14 14 // 15 15 16 #include <time.h> // tzset 16 17 #include "startup.hfa" 17 #include <time.h> // tzset18 18 19 19 extern "C" { 20 staticvoid __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) ));20 void __cfaabi_appready_startup( void ) __attribute__(( constructor( STARTUP_PRIORITY_APPREADY ) )); 21 21 void __cfaabi_appready_startup( void ) { 22 22 tzset(); // initialize time global variables … … 27 27 } // __cfaabi_appready_startup 28 28 29 staticvoid __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) ));29 void __cfaabi_appready_shutdown( void ) __attribute__(( destructor( STARTUP_PRIORITY_APPREADY ) )); 30 30 void __cfaabi_appready_shutdown( void ) { 31 31 #ifdef __CFA_DEBUG__ -
libcfa/src/time.hfa
re0c235c r4834563 10 10 // Created On : Wed Mar 14 23:18:57 2018 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Jan 5 19:01:07202013 // Update Count : 65 212 // Last Modified On : Mon Jan 6 12:50:16 2020 13 // Update Count : 653 14 14 // 15 15 … … 207 207 } // ?{} 208 208 209 //######################### C time #########################210 211 static inline char * ctime( time_t tp ) { char * buf = ctime( &tp ); buf[24] = '\0'; return buf; }212 static inline char * ctime_r( time_t tp, char * buf ) { ctime_r( &tp, buf ); buf[24] = '\0'; return buf; }213 static inline tm * gmtime( time_t tp ) { return gmtime( &tp ); }214 static inline tm * gmtime_r( time_t tp, tm * result ) { return gmtime_r( &tp, result ); }215 static inline tm * localtime( time_t tp ) { return localtime( &tp ); }216 static inline tm * localtime_r( time_t tp, tm * result ) { return localtime_r( &tp, result ); }217 218 //######################### Clock #########################219 220 struct Clock { // private221 Duration offset; // for virtual clock: contains offset from real-time222 };223 224 static inline {225 void resetClock( Clock & clk, Duration adj ) with( clk ) {226 offset = adj + __timezone`s; // timezone (global) is (UTC - local time) in seconds227 } // resetClock228 229 void ?{}( Clock & clk, Duration adj ) { resetClock( clk, adj ); }230 231 Duration getResNsec() {232 struct timespec res;233 clock_getres( CLOCK_REALTIME, &res );234 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;235 } // getRes236 237 Duration getRes() {238 struct timespec res;239 clock_getres( CLOCK_REALTIME_COARSE, &res );240 return ((int64_t)res.tv_sec * TIMEGRAN + res.tv_nsec)`ns;241 } // getRes242 243 Time getTimeNsec() { // with nanoseconds244 timespec curr;245 clock_gettime( CLOCK_REALTIME, &curr );246 return (Time){ curr };247 } // getTimeNsec248 249 Time getTime() { // without nanoseconds250 timespec curr;251 clock_gettime( CLOCK_REALTIME_COARSE, &curr );252 curr.tv_nsec = 0;253 return (Time){ curr };254 } // getTime255 256 Time getTime( Clock & clk ) with( clk ) {257 return getTime() + offset;258 } // getTime259 260 Time ?()( Clock & clk ) with( clk ) { // alternative syntax261 return getTime() + offset;262 } // getTime263 264 timeval getTime( Clock & clk ) {265 return (timeval){ clk() };266 } // getTime267 268 tm getTime( Clock & clk ) with( clk ) {269 tm ret;270 localtime_r( getTime( clk ).tv_sec, &ret );271 return ret;272 } // getTime273 274 Time getCPUTime() {275 timespec ts;276 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts );277 return (Time){ ts };278 } // getCPUTime279 } // distribution280 281 209 // Local Variables: // 282 210 // mode: c //
Note: See TracChangeset
for help on using the changeset viewer.