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 checking of the guard condition. #204

Merged
merged 2 commits into from
Jun 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
9 changes: 7 additions & 2 deletions rmw_zenoh_cpp/src/detail/guard_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,21 @@ void GuardCondition::detach_condition()
condition_variable_ = nullptr;
}

bool GuardCondition::has_triggered() const
{
std::lock_guard<std::mutex> lock(internal_mutex_);
return has_triggered_;
}

///=============================================================================
bool GuardCondition::get_and_reset_trigger()
{
std::lock_guard<std::mutex> lock(internal_mutex_);
bool ret = has_triggered_;

// There is no data associated with the guard condition, so as soon as the callers asks about the
// state, we can immediately reset and get ready for the next trigger.
has_triggered_ = false;

return ret;
}

} // namespace rmw_zenoh_cpp
2 changes: 2 additions & 0 deletions rmw_zenoh_cpp/src/detail/guard_condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class GuardCondition final

void detach_condition();

bool has_triggered() const;

bool get_and_reset_trigger();

private:
Expand Down
14 changes: 6 additions & 8 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3137,20 +3137,18 @@ rmw_destroy_wait_set(rmw_wait_set_t * wait_set)
}

static bool has_triggered_condition(
rmw_subscriptions_t * subscriptions,
rmw_guard_conditions_t * guard_conditions,
rmw_services_t * services,
rmw_clients_t * clients,
rmw_events_t * events)
const rmw_subscriptions_t * const subscriptions,
const rmw_guard_conditions_t * const guard_conditions,
const rmw_services_t * const services,
const rmw_clients_t * const clients,
const rmw_events_t * const events)
{
static_cast<void>(events);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow does this mean we were never actually checking for events?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the code for checking events is down below. We just forgot to remove this (dead) line of code when we actually did implement events.


if (guard_conditions) {
for (size_t i = 0; i < guard_conditions->guard_condition_count; ++i) {
rmw_zenoh_cpp::GuardCondition * gc =
static_cast<rmw_zenoh_cpp::GuardCondition *>(guard_conditions->guard_conditions[i]);
if (gc != nullptr) {
if (gc->get_and_reset_trigger()) {
if (gc->has_triggered()) {
return true;
}
}
Expand Down
Loading