Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #include "../../include/ecl/time_lite/functions_rt.hpp"
00013 #include <errno.h>
00014
00015
00016
00017
00018
00019 #if defined(ECL_HAS_RT_TIMERS)
00020
00021
00022
00023
00024
00025 namespace ecl {
00026
00027 TimeError epoch_time(TimeStructure &time) {
00028
00029
00030
00031 #ifdef ECL_HAS_CLOCK_MONOTONIC
00032 int result = clock_gettime(CLOCK_MONOTONIC,&time);
00033 #else
00034 int result = clock_gettime(CLOCK_REALTIME,&time);
00035 #endif
00036 switch (result) {
00037 case(0) : { return TimeError(NoError); }
00038 case(EFAULT) : { return TimeError(MemoryError); }
00039 case(EINVAL) : { return TimeError(ArgNotSupportedError); }
00040 case(EPERM) : { return TimeError(PermissionsError); }
00041 default : { return TimeError(UnknownError); }
00042 }
00043 }
00044
00045 TimeError sleep_until(const TimeStructure &time) {
00046
00047 #ifdef ECL_HAS_CLOCK_MONOTONIC
00048 int result = clock_nanosleep(CLOCK_MONOTONIC,TIMER_ABSTIME,&time,NULL);
00049 #else
00050 int result = clock_nanosleep(CLOCK_REALTIME,TIMER_ABSTIME,&time,NULL);
00051 #endif
00052 switch (result) {
00053 case(0) : { return TimeError(NoError); }
00054 case(EFAULT) : { return TimeError(MemoryError); }
00055 case(EINTR) : { return TimeError(InterruptedError); }
00056 case(EINVAL) : { return TimeError(OutOfRangeError); }
00057 default : { return TimeError(UnknownError); }
00058 }
00059 }
00060 TimeError sleep(const TimeStructure &time) {
00061 int result = nanosleep(&time, NULL);
00062 switch (result) {
00063 case(0) : { return TimeError(NoError); }
00064 case(EFAULT) : { return TimeError(MemoryError); }
00065 case(EINTR) : { return TimeError(InterruptedError); }
00066 case(EINVAL) : { return TimeError(OutOfRangeError); }
00067 default : { return TimeError(UnknownError); }
00068 }
00069 }
00070
00071 }
00072
00073 #endif