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

Publisher dequeue changes #125

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions include/cactus_rt/ros2/ros2_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@

namespace cactus_rt::ros2 {

class Ros2ExecutorThread;

class Ros2Adapter {
friend class Ros2ExecutorThread;

public:
struct Config {
/**
Expand Down
3 changes: 1 addition & 2 deletions src/cactus_rt/ros2/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ void Ros2ExecutorThread::Run() {
executor_->spin_once();
}

// Execute one more time to ensure everything is processed.
executor_->spin_once();
ros2_adapter_->DrainQueues();

executor_->remove_node(node_ptr);
}
Expand Down
16 changes: 9 additions & 7 deletions src/cactus_rt/ros2/ros2_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ void Ros2Adapter::TimerCallback() {
void Ros2Adapter::DrainQueues() {
const std::scoped_lock lock(mut_);

for (const auto& publisher : publishers_) {
// Hopefully the thread is not publishing so quickly that a single
// publisher monopolizes all resources. That said, if that happens the
// program is likely in bigger trouble anyway.
//
// TODO: make it so we dequeue once.
publisher->FullyDrainAndPublishToRos();
bool has_data = true;
while (has_data) {
has_data = false;

for (const auto& publisher : publishers_) {
if (publisher->DequeueAndPublishToRos()) {
has_data = true;
}
}
}
}

Expand Down
Loading