Skip to content

Commit

Permalink
Move the hasData checks for non-blocking wait 'timeout' higher (#158)
Browse files Browse the repository at this point in the history
Avoids the data having been already cleared for guard conditions
  • Loading branch information
dhood authored Oct 18, 2017
1 parent da50d27 commit 0cf51dc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions rmw_fastrtps_cpp/src/rmw_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ rmw_wait(
// after we check, it will be caught on the next call to this function).
lock.unlock();

// Even if this was a non-blocking wait, signal a timeout if there's no data.
// This makes the return behavior consistent with rcl expectations for zero timeout value.
// Do this before detaching the listeners because the data gets cleared for guard conditions.
bool hasData = check_waitset_for_data(subscriptions, guard_conditions, services, clients);
if (!hasData && wait_timeout && wait_timeout->sec == 0 && wait_timeout->nsec == 0) {
timeout = true;
}

for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
void * data = subscriptions->subscribers[i];
CustomSubscriberInfo * custom_subscriber_info = static_cast<CustomSubscriberInfo *>(data);
Expand Down Expand Up @@ -231,11 +239,6 @@ rmw_wait(
}
}
}
// Make timeout behavior consistent with rcl expectations for zero timeout value
bool hasData = check_waitset_for_data(subscriptions, guard_conditions, services, clients);
if (!hasData && wait_timeout && wait_timeout->sec == 0 && wait_timeout->nsec == 0) {
return RMW_RET_TIMEOUT;
}

return timeout ? RMW_RET_TIMEOUT : RMW_RET_OK;
}
Expand Down

0 comments on commit 0cf51dc

Please sign in to comment.