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 TimedConditionVariable hanging forever when now() > max_blocking_time #1000

Closed
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
12 changes: 10 additions & 2 deletions include/fastrtps/utils/TimedConditionVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ class TimedConditionVariable
std::function<bool()> predicate)
{
bool ret_value = true;
std::chrono::nanoseconds nsecs = max_blocking_time - std::chrono::steady_clock::now();
auto now = std::chrono::steady_clock::now();
if (now > max_blocking_time) {
return predicate();
}
std::chrono::nanoseconds nsecs = max_blocking_time - now;
struct timespec max_wait = { 0, 0 };
clock_gettime(CLOCK_REALTIME, &max_wait);
nsecs = nsecs + std::chrono::nanoseconds(max_wait.tv_nsec);
Expand All @@ -138,7 +142,11 @@ class TimedConditionVariable
std::unique_lock<Mutex>& lock,
const std::chrono::steady_clock::time_point& max_blocking_time)
{
std::chrono::nanoseconds nsecs = max_blocking_time - std::chrono::steady_clock::now();
auto now = std::chrono::steady_clock::now();
if (now > max_blocking_time) {
return false;
}
std::chrono::nanoseconds nsecs = max_blocking_time - now;
struct timespec max_wait = { 0, 0 };
clock_gettime(CLOCK_REALTIME, &max_wait);
nsecs = nsecs + std::chrono::nanoseconds(max_wait.tv_nsec);
Expand Down