-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add MonotonicTime for use with timeouts #55
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,6 +167,29 @@ namespace ros | |
nsec = nsec_sum; | ||
#endif | ||
} | ||
|
||
void ros_monotonictime(uint32_t& sec, uint32_t& nsec) | ||
#ifndef WIN32 | ||
throw(NoHighPerformanceTimersException) | ||
#endif | ||
{ | ||
#ifndef WIN32 | ||
#if HAS_CLOCK_GETTIME | ||
timespec start; | ||
clock_gettime(CLOCK_MONOTONIC, &start); | ||
sec = start.tv_sec; | ||
nsec = start.tv_nsec; | ||
#else | ||
// what to do if clock_gettime is not available??? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't merge this with this code path in here, since I'm pretty sure that it isn't monotonic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. I would actually just leave the case when |
||
struct timeval timeofday; | ||
gettimeofday(&timeofday,NULL); | ||
sec = timeofday.tv_sec; | ||
nsec = timeofday.tv_usec * 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is possible to avoid this on macOS (also other BSD systems which don't have I've implemented something that is monotonic and works on Linux, and macOS for ROS 2: There's also something for Windows: You're welcome to steal those implementations if you like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, it's been too long since I've looked at it to respond intelligently 😄, but I'll review the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
#endif | ||
#else | ||
ros_walltime(sec, nsec); | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a great place to use However, I'm not sure that would be acceptable within |
||
} | ||
/** | ||
* @brief Simple representation of the rt library nanosleep function. | ||
*/ | ||
|
@@ -389,6 +412,17 @@ namespace ros | |
return true; | ||
} | ||
|
||
bool MonotonicTime::sleepUntil(const MonotonicTime& end) | ||
{ | ||
WallDuration d(end - MonotonicTime::now()); | ||
if (d > WallDuration(0)) | ||
{ | ||
return d.sleep(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool Duration::sleep() const | ||
{ | ||
if (Time::useSystemTime()) | ||
|
@@ -444,6 +478,13 @@ namespace ros | |
return t; | ||
} | ||
|
||
MonotonicTime MonotonicTime::now() | ||
{ | ||
MonotonicTime t; | ||
ros_monotonictime(t.sec, t.nsec); | ||
|
||
return t; | ||
} | ||
std::ostream &operator<<(std::ostream& os, const WallDuration& rhs) | ||
{ | ||
boost::io::ios_all_saver s(os); | ||
|
@@ -505,6 +546,7 @@ namespace ros | |
|
||
template class TimeBase<Time, Duration>; | ||
template class TimeBase<WallTime, WallDuration>; | ||
template class TimeBase<MonotonicTime, WallDuration>; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be noted here that it is unaffected by ROS time, just like "wall" time is not.