14 #include "../../include/ecl/time_lite/functions_pos.hpp" 21 #if defined(ECL_HAS_POSIX_TIMERS) 29 TimeError epoch_time(TimeStructure &time) {
31 int result = gettimeofday(&tv, NULL);
33 time.tv_sec = tv.tv_sec;
34 time.tv_nsec = tv.tv_usec*1000;
44 TimeError sleep_until(
const TimeStructure &time) {
45 TimeStructure current_time, sleep_time;
47 TimeError error = epoch_time(current_time);
48 if ( error.flag() !=
NoError ) {
return error; }
53 if ( current_time.tv_sec > time.tv_sec ) {
55 }
else if ( current_time.tv_sec == time.tv_sec ) {
56 if ( current_time.tv_nsec > time.tv_nsec ) {
60 sleep_time.tv_sec = time.tv_sec - current_time.tv_sec;
61 if ( current_time.tv_nsec <= time.tv_nsec ) {
62 sleep_time.tv_nsec = time.tv_nsec - current_time.tv_nsec;
64 sleep_time.tv_sec -= 1;
65 sleep_time.tv_nsec = 1000000000L - current_time.tv_nsec + time.tv_nsec;
67 int result = nanosleep(&sleep_time, NULL);
69 case(0) : {
return TimeError(
NoError); }
76 TimeError sleep(
const TimeStructure &time) {
77 int result = nanosleep(&time, NULL);
79 case(0) : {
return TimeError(
NoError); }