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

Revamp how we compute the return value for rmw_wait(). #209

Merged
merged 1 commit into from
Jun 24, 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
21 changes: 15 additions & 6 deletions rmw_zenoh_cpp/src/rmw_zenoh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3397,25 +3397,24 @@ rmw_wait(

bool skip_wait = check_and_attach_condition(
subscriptions, guard_conditions, services, clients, events, wait_set_data);
bool wait_result = true;

if (!skip_wait) {
std::unique_lock<std::mutex> lock(wait_set_data->condition_mutex);

// According to the RMW documentation, if wait_timeout is NULL that means
// "wait forever", if it specified by 0 it means "never wait", and if it is anything else wait
// "wait forever", if it specified as 0 it means "never wait", and if it is anything else wait
// for that amount of time.
if (wait_timeout == nullptr) {
wait_set_data->condition_variable.wait(lock);
} else {
if (wait_timeout->sec != 0 || wait_timeout->nsec != 0) {
std::cv_status wait_status = wait_set_data->condition_variable.wait_for(
wait_set_data->condition_variable.wait_for(
lock, std::chrono::nanoseconds(wait_timeout->nsec + RCUTILS_S_TO_NS(wait_timeout->sec)));
wait_result = wait_status == std::cv_status::no_timeout;
}
}
}

bool wait_result = false;

// According to the documentation for rmw_wait in rmw.h, entries in the various arrays that have
// *not* been triggered should be set to NULL
if (guard_conditions) {
Expand All @@ -3428,6 +3427,8 @@ rmw_wait(
if (!gc->detach_condition_and_trigger_set()) {
// Setting to nullptr lets rcl know that this guard condition is not ready
guard_conditions->guard_conditions[i] = nullptr;
} else {
wait_result = true;
}
}
}
Expand All @@ -3442,6 +3443,8 @@ rmw_wait(
if (event_data->detach_condition_and_event_queue_is_empty(zenoh_event_it->second)) {
// Setting to nullptr lets rcl know that this subscription is not ready
events->events[i] = nullptr;
} else {
wait_result = true;
}
}
}
Expand All @@ -3459,6 +3462,8 @@ rmw_wait(
if (sub_data->detach_condition_and_queue_is_empty()) {
// Setting to nullptr lets rcl know that this subscription is not ready
subscriptions->subscribers[i] = nullptr;
} else {
wait_result = true;
}
}
}
Expand All @@ -3473,6 +3478,8 @@ rmw_wait(
if (serv_data->detach_condition_and_queue_is_empty()) {
// Setting to nullptr lets rcl know that this service is not ready
services->services[i] = nullptr;
} else {
wait_result = true;
}
}
}
Expand All @@ -3488,11 +3495,13 @@ rmw_wait(
if (client_data->detach_condition_and_queue_is_empty()) {
// Setting to nullptr lets rcl know that this client is not ready
clients->clients[i] = nullptr;
} else {
wait_result = true;
}
}
}

return (skip_wait || wait_result) ? RMW_RET_OK : RMW_RET_TIMEOUT;
return wait_result ? RMW_RET_OK : RMW_RET_TIMEOUT;
}

//==============================================================================
Expand Down
Loading