From 4bbbedbb7ea3fd8179e7f021fd9471eddd394f35 Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Sat, 1 Jun 2019 12:29:38 -0700 Subject: lib: Replace uhd::get_system_time() with steady_clock Benchmarks show that using C++ chrono features beats uhd::get_system_time(), and the latter is simply not appropriate unless a uhd::time_spec_t is required. --- .../uhdlib/usrp/common/recv_packet_demuxer_3000.hpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'host/lib/include/uhdlib/usrp/common') diff --git a/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp b/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp index 3a17b864e..54ae10908 100644 --- a/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp +++ b/host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp @@ -8,7 +8,6 @@ #ifndef INCLUDED_LIBUHD_USRP_COMMON_RECV_PACKET_DEMUXER_3000_HPP #define INCLUDED_LIBUHD_USRP_COMMON_RECV_PACKET_DEMUXER_3000_HPP -#include #include #include #include @@ -18,6 +17,7 @@ #include #include #include +#include #include namespace uhd{ namespace usrp{ @@ -36,15 +36,19 @@ namespace uhd{ namespace usrp{ transport::managed_recv_buffer::sptr get_recv_buff(const uint32_t sid, const double timeout) { - const time_spec_t exit_time = - time_spec_t(timeout) + uhd::get_system_time(); + const auto exit_time = std::chrono::high_resolution_clock::now() + + std::chrono::microseconds(int64_t(timeout * 1e6)); transport::managed_recv_buffer::sptr buff; buff = _internal_get_recv_buff(sid, timeout); while (not buff) //loop until timeout { - const time_spec_t delta = exit_time - uhd::get_system_time(); - const double new_timeout = delta.get_real_secs(); - if (new_timeout < 0.0) break; + const auto delta = exit_time - std::chrono::high_resolution_clock::now(); + const double new_timeout = + std::chrono::duration_cast>(delta) + .count(); + if (new_timeout < 0.0) { + break; + } buff = _internal_get_recv_buff(sid, new_timeout); } return buff; -- cgit v1.2.3