Skip to content

Commit

Permalink
Revert "Use steady_clock instead of high_resolution_clock for status …
Browse files Browse the repository at this point in the history
…checks (high_resolution_clock might not be steady depending on STL impl)"

This reverts commit d69eb91.
  • Loading branch information
MiguelCompany committed Aug 29, 2024
1 parent 3d20ab3 commit f94d111
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/cpp/rtps/transport/shared_mem/SharedMemGlobal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SharedMemGlobal

struct PortNode
{
alignas(8) std::atomic<std::chrono::steady_clock::rep> last_listeners_status_check_time_ms;
alignas(8) std::atomic<std::chrono::high_resolution_clock::rep> last_listeners_status_check_time_ms;
alignas(8) std::atomic<uint32_t> ref_counter;

SharedMemSegment::Offset buffer;
Expand Down Expand Up @@ -324,17 +324,17 @@ class SharedMemGlobal

port_node->last_listeners_status_check_time_ms.exchange(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count());
std::chrono::high_resolution_clock::now().time_since_epoch()).count());

return listeners_found == port_node->num_listeners;
}

void run()
{
auto now = std::chrono::steady_clock::now();
auto now = std::chrono::high_resolution_clock::now();

auto timeout_elapsed = [](
std::chrono::steady_clock::time_point& now,
std::chrono::high_resolution_clock::time_point& now,
const PortContext& port_context)
{
return std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
Expand Down Expand Up @@ -869,14 +869,14 @@ class SharedMemGlobal
throw std::runtime_error("port is marked as not ok");
}

auto t0 = std::chrono::steady_clock::now();
auto t0 = std::chrono::high_resolution_clock::now();

// If in any moment during the timeout all waiting listeners are OK
// then the port is OK
bool is_check_ok = false;
while ( !is_check_ok &&
std::chrono::duration_cast<std::chrono::milliseconds>
(std::chrono::steady_clock::now() - t0).count() < node_->healthy_check_timeout_ms)
(std::chrono::high_resolution_clock::now() - t0).count() < node_->healthy_check_timeout_ms)
{
{
std::unique_lock<SharedMemSegment::mutex> lock(node_->empty_cv_mutex);
Expand Down Expand Up @@ -1279,7 +1279,7 @@ class SharedMemGlobal
port_node->healthy_check_timeout_ms = healthy_check_timeout_ms;
port_node->last_listeners_status_check_time_ms =
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now().time_since_epoch()).count();
std::chrono::high_resolution_clock::now().time_since_epoch()).count();
port_node->port_wait_timeout_ms = healthy_check_timeout_ms / 3;
port_node->max_buffer_descriptors = max_buffer_descriptors;
std::fill_n(port_node->listeners_status, PortNode::LISTENERS_STATUS_SIZE, PortNode::ListenerStatus());
Expand Down

0 comments on commit f94d111

Please sign in to comment.