aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-06-01 12:29:38 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:12 -0800
commit4bbbedbb7ea3fd8179e7f021fd9471eddd394f35 (patch)
treefcfc87c04bedfccdf16a7d0f64dcbb6a8d7f64b0
parent56f21097483da8aa5d8787a75a1b22a0c4c41313 (diff)
downloaduhd-4bbbedbb7ea3fd8179e7f021fd9471eddd394f35.tar.gz
uhd-4bbbedbb7ea3fd8179e7f021fd9471eddd394f35.tar.bz2
uhd-4bbbedbb7ea3fd8179e7f021fd9471eddd394f35.zip
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.
-rw-r--r--host/lib/include/uhdlib/usrp/common/recv_packet_demuxer_3000.hpp16
-rw-r--r--host/lib/include/uhdlib/utils/atomic.hpp7
2 files changed, 14 insertions, 9 deletions
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 <uhdlib/utils/system_time.hpp>
#include <uhd/config.hpp>
#include <uhd/transport/zero_copy.hpp>
#include <uhd/utils/log.hpp>
@@ -18,6 +17,7 @@
#include <boost/enable_shared_from_this.hpp>
#include <queue>
#include <map>
+#include <chrono>
#include <stdint.h>
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<std::chrono::duration<double>>(delta)
+ .count();
+ if (new_timeout < 0.0) {
+ break;
+ }
buff = _internal_get_recv_buff(sid, new_timeout);
}
return buff;
diff --git a/host/lib/include/uhdlib/utils/atomic.hpp b/host/lib/include/uhdlib/utils/atomic.hpp
index 5436eea81..303df1bc9 100644
--- a/host/lib/include/uhdlib/utils/atomic.hpp
+++ b/host/lib/include/uhdlib/utils/atomic.hpp
@@ -10,9 +10,9 @@
#include <uhd/config.hpp>
#include <uhd/types/time_spec.hpp>
-#include <uhdlib/utils/system_time.hpp>
#include <boost/thread/thread.hpp>
#include <atomic>
+#include <chrono>
namespace uhd{
@@ -31,9 +31,10 @@ namespace uhd{
const double timeout
){
if (cond == value) return true;
- const time_spec_t exit_time = uhd::get_system_time() + time_spec_t(timeout);
+ const auto exit_time = std::chrono::high_resolution_clock::now()
+ + std::chrono::microseconds(int64_t(timeout * 1e6));
while (cond != value) {
- if (uhd::get_system_time() > exit_time) {
+ if (std::chrono::high_resolution_clock::now() > exit_time) {
return false;
}
boost::this_thread::interruption_point();