Skip to content

Commit

Permalink
Lock the condition mutex during setup
Browse files Browse the repository at this point in the history
Otherwise one-shot notifications will be missed and we'll wait for them forever
  • Loading branch information
dhood authored and dirk-thomas committed Aug 22, 2017
1 parent 8b17aaf commit a173bfa
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rmw_fastrtps_cpp/src/rmw_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ rmw_wait(
return RMW_RET_ERROR;
}

// Lock the condition mutex as we're attaching it.
// Otherwise, we might miss a notification of the condition variable if it occurs during setup
// before we start waiting, and that can cause us to wait forever.
std::unique_lock<std::mutex> lock(*conditionMutex);

for (size_t i = 0; i < subscriptions->subscriber_count; ++i) {
void * data = subscriptions->subscribers[i];
CustomSubscriberInfo * custom_subscriber_info = static_cast<CustomSubscriberInfo *>(data);
Expand All @@ -124,8 +129,6 @@ rmw_wait(
}
}

std::unique_lock<std::mutex> lock(*conditionMutex);

// First check variables.
// If wait_timeout is null, wait indefinitely (so we have to wait)
// If wait_timeout is not null and either of its fields are nonzero, we have to wait
Expand Down

0 comments on commit a173bfa

Please sign in to comment.