Skip to content
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

Fix urg_sim CPU usage #150

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::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;

Check warning on line 773 in src/urg_sim/urg_sim.cpp

View check run for this annotation

Codecov / codecov/patch

src/urg_sim/urg_sim.cpp#L772-L773

Added lines #L772 - L773 were not covered by tests
}
keepalive_timer.expires_from_now(boost::posix_time::hours(1));
keepalive_timer.async_wait(keepalive);
};

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