aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/utils/system_time.cpp
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2019-06-01 12:31:17 -0700
committerMartin Braun <martin.braun@ettus.com>2019-11-26 11:49:12 -0800
commitf7cb6ee0d67afaed499cec9e8e8d0d481a65dd29 (patch)
tree20d7381f78b4f463330cb7042b36faddb95aaa60 /host/lib/utils/system_time.cpp
parent4bbbedbb7ea3fd8179e7f021fd9471eddd394f35 (diff)
downloaduhd-f7cb6ee0d67afaed499cec9e8e8d0d481a65dd29.tar.gz
uhd-f7cb6ee0d67afaed499cec9e8e8d0d481a65dd29.tar.bz2
uhd-f7cb6ee0d67afaed499cec9e8e8d0d481a65dd29.zip
lib: Simplify implementation of uhd::get_system_time() to use <chrono>
uhd::get_system_time() is currently only used in USRP1 code, and it turns out that our "optimized", platform-dependent implementation still is a little slower than straight-up chrono. We therefore remove all the special cases, and replace them with a single, standard solution.
Diffstat (limited to 'host/lib/utils/system_time.cpp')
-rw-r--r--host/lib/utils/system_time.cpp54
1 files changed, 8 insertions, 46 deletions
diff --git a/host/lib/utils/system_time.cpp b/host/lib/utils/system_time.cpp
index 20b6dc429..71fcd3fff 100644
--- a/host/lib/utils/system_time.cpp
+++ b/host/lib/utils/system_time.cpp
@@ -5,50 +5,12 @@
//
#include <uhdlib/utils/system_time.hpp>
-
-using namespace uhd;
-
-#ifdef HAVE_CLOCK_GETTIME
-#include <time.h>
-time_spec_t uhd::get_system_time(void){
- timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts);
- return time_spec_t(ts.tv_sec, ts.tv_nsec, 1e9);
-}
-#endif /* HAVE_CLOCK_GETTIME */
-
-
-#ifdef HAVE_MACH_ABSOLUTE_TIME
-#include <mach/mach_time.h>
-time_spec_t uhd::get_system_time(void){
- mach_timebase_info_data_t info; mach_timebase_info(&info);
- intmax_t nanosecs = mach_absolute_time()*info.numer/info.denom;
- return time_spec_t::from_ticks(nanosecs, 1e9);
-}
-#endif /* HAVE_MACH_ABSOLUTE_TIME */
-
-
-#ifdef HAVE_QUERY_PERFORMANCE_COUNTER
-#include <Windows.h>
-time_spec_t uhd::get_system_time(void){
- LARGE_INTEGER counts, freq;
- QueryPerformanceCounter(&counts);
- QueryPerformanceFrequency(&freq);
- return time_spec_t::from_ticks(counts.QuadPart, double(freq.QuadPart));
-}
-#endif /* HAVE_QUERY_PERFORMANCE_COUNTER */
-
-
-#ifdef HAVE_MICROSEC_CLOCK
-#include <boost/date_time/posix_time/posix_time.hpp>
-namespace pt = boost::posix_time;
-time_spec_t uhd::get_system_time(void){
- pt::ptime time_now = pt::microsec_clock::universal_time();
- pt::time_duration time_dur = time_now - pt::from_time_t(0);
- return time_spec_t(
- int64_t(time_dur.total_seconds()),
- long(time_dur.fractional_seconds()),
- double(pt::time_duration::ticks_per_second())
- );
+#include <chrono>
+
+uhd::time_spec_t uhd::get_system_time(void)
+{
+ const auto now = std::chrono::steady_clock::now().time_since_epoch();
+ const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(now);
+ const auto nanoseconds = std::chrono::duration_cast<std::chrono::nanoseconds>(now-seconds);
+ return uhd::time_spec_t(seconds.count(), nanoseconds.count(), 1e9);
}
-#endif /* HAVE_MICROSEC_CLOCK */
-