12 #include "../../include/ecl/time_lite/functions_mac.hpp" 19 #if defined(ECL_HAS_MACH_TIMERS) 27 TimeError epoch_time(TimeStructure &time) {
29 int result = gettimeofday(&tv, NULL);
31 time.tv_sec = tv.tv_sec;
32 time.tv_nsec = tv.tv_usec*1000;
43 TimeError sleep_until(
const TimeStructure &time) {
44 TimeStructure current_time, sleep_time;
46 TimeError error = epoch_time(current_time);
47 if ( error.flag() !=
NoError ) {
return error; }
52 if ( current_time.tv_sec > time.tv_sec ) {
54 }
else if ( current_time.tv_sec == time.tv_sec ) {
55 if ( current_time.tv_nsec > time.tv_nsec ) {
59 sleep_time.tv_sec = time.tv_sec - current_time.tv_sec;
60 if ( current_time.tv_nsec <= time.tv_nsec ) {
61 sleep_time.tv_nsec = time.tv_nsec - current_time.tv_nsec;
63 sleep_time.tv_sec -= 1;
64 sleep_time.tv_nsec = 1000000000L - current_time.tv_nsec + time.tv_nsec;
66 int result = nanosleep(&sleep_time, NULL);
68 case(0) : {
return TimeError(
NoError); }
76 TimeError sleep(
const TimeStructure &time) {
77 int result = nanosleep(&time, NULL);
79 case(0) : {
return TimeError(
NoError); }