Skip to content

Commit

Permalink
Duration cast for clocks with poor resolutions
Browse files Browse the repository at this point in the history
Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
  • Loading branch information
sloretz committed Dec 13, 2021
1 parent 0a0c5a3 commit 4fe3c8d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions rclpy/src/rclpy/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ void Event::wait_until(std::shared_ptr<Clock> clock, rcl_time_point_t until)
throw RCLError("failed to subtract times");
}

const typename ClockType::time_point chrono_until =
chrono_entry + std::chrono::nanoseconds(delta_t.nanoseconds);
// Cast because system clock resolution is be too big for nanoseconds on Windows & OSX
const typename ClockType::time_point chrono_until = chrono_entry +
std::chrono::duration_cast<typename ClockType::duration>(
std::chrono::nanoseconds(delta_t.nanoseconds));

// Could be a long wait, release the gil
py::gil_scoped_release release;
Expand Down

0 comments on commit 4fe3c8d

Please sign in to comment.