Skip to content

Commit

Permalink
Refs #17148. Avoid try_lock_until on DataReaderImpl.
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Company <[email protected]>
  • Loading branch information
MiguelCompany committed Feb 10, 2023
1 parent 5a3ca1e commit 4d07531
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/cpp/fastdds/subscriber/DataReaderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,19 +494,18 @@ ReturnCode_t DataReaderImpl::read_or_take(
return code;
}

auto max_blocking_time = std::chrono::steady_clock::now() +
#if HAVE_STRICT_REALTIME
auto max_blocking_time = std::chrono::steady_clock::now() +
std::chrono::microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time));
#else
std::chrono::hours(24);
#endif // if HAVE_STRICT_REALTIME

std::unique_lock<RecursiveTimedMutex> lock(reader_->getMutex(), std::defer_lock);

if (!lock.try_lock_until(max_blocking_time))
{
return ReturnCode_t::RETCODE_TIMEOUT;
}
#else
std::lock_guard<RecursiveTimedMutex> _(reader_->getMutex());
#endif // if HAVE_STRICT_REALTIME

set_read_communication_status(false);

Expand Down Expand Up @@ -693,20 +692,20 @@ ReturnCode_t DataReaderImpl::read_or_take_next_sample(
return ReturnCode_t::RETCODE_NO_DATA;
}

auto max_blocking_time = std::chrono::steady_clock::now() +
#if HAVE_STRICT_REALTIME
auto max_blocking_time = std::chrono::steady_clock::now() +
std::chrono::microseconds(::TimeConv::Time_t2MicroSecondsInt64(qos_.reliability().max_blocking_time));
#else
std::chrono::hours(24);
#endif // if HAVE_STRICT_REALTIME

std::unique_lock<RecursiveTimedMutex> lock(reader_->getMutex(), std::defer_lock);

if (!lock.try_lock_until(max_blocking_time))
{
return ReturnCode_t::RETCODE_TIMEOUT;
}

#else
std::lock_guard<RecursiveTimedMutex> _(reader_->getMutex());
#endif // if HAVE_STRICT_REALTIME

set_read_communication_status(false);

auto it = history_.lookup_available_instance(HANDLE_NIL, false);
Expand Down

0 comments on commit 4d07531

Please sign in to comment.