Skip to content

Commit

Permalink
Fix urg_sim CPU usage (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
at-wat committed Apr 8, 2024
1 parent 6f2f279 commit c27faaa
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/urg_sim/urg_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,24 @@ void URGSimulator::spin()

void URGSimulator::fifo(boost::asio::io_service& fifo)
{
boost::asio::deadline_timer keepalive_timer(fifo);
std::function<void(const boost::system::error_code& ec)> keepalive;
keepalive = [&fifo, &keepalive](const boost::system::error_code& ec)

keepalive = [&keepalive_timer, &keepalive](const boost::system::error_code& ec)
{
boost::asio::deadline_timer keepalive_timer(fifo);
if (ec == boost::asio::error::operation_aborted)
{
return;
}
if (ec)
{
std::cerr << "fifo keepalive error: " << ec << std::endl;
return;
}
keepalive_timer.expires_from_now(boost::posix_time::hours(1));
keepalive_timer.async_wait(keepalive);
};

while (!killed_)
{
keepalive(boost::system::error_code());
Expand Down

0 comments on commit c27faaa

Please sign in to comment.