diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-02-03 18:12:30 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2018-04-10 22:27:21 +0200 |
commit | 2bc4e35410bef91d1c4b0135832828612f540d26 (patch) | |
tree | 8ab2b0bba29c1e029d5563e078ebde6dcc49553f /src/output | |
parent | b20358ac28feb93d8196d7a6106aa77ca8592908 (diff) | |
download | dabmod-2bc4e35410bef91d1c4b0135832828612f540d26.tar.gz dabmod-2bc4e35410bef91d1c4b0135832828612f540d26.tar.bz2 dabmod-2bc4e35410bef91d1c4b0135832828612f540d26.zip |
Use std::future instead of boost::packaged_task in USRPTime
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/USRPTime.cpp | 41 | ||||
-rw-r--r-- | src/output/USRPTime.h | 5 |
2 files changed, 17 insertions, 29 deletions
diff --git a/src/output/USRPTime.cpp b/src/output/USRPTime.cpp index 56bdf50..39b0e5a 100644 --- a/src/output/USRPTime.cpp +++ b/src/output/USRPTime.cpp @@ -204,43 +204,32 @@ void USRPTime::check_gps() if (gpsfix_needs_check() and time_last_check + checkinterval < time_now) { time_last_check = time_now; - // Alternate between launching thread and checking the - // result. - if (gps_fix_task.joinable()) { - if (gps_fix_future.has_value()) { - - gps_fix_future.wait(); - - gps_fix_task.join(); - - if (not gps_fix_future.get()) { - if (num_checks_without_gps_fix == 0) { - etiLog.level(alert) << "OutputUHD: GPS Time Lock lost"; - } - num_checks_without_gps_fix++; + // Alternate between launching task and checking the result. + if (gps_fix_future.valid()) { + if (not gps_fix_future.get()) { + if (num_checks_without_gps_fix == 0) { + etiLog.level(alert) << "OutputUHD: GPS Time Lock lost"; } - else { - if (num_checks_without_gps_fix) { - etiLog.level(info) << "OutputUHD: GPS Time Lock recovered"; - } - num_checks_without_gps_fix = 0; + num_checks_without_gps_fix++; + } + else { + if (num_checks_without_gps_fix) { + etiLog.level(info) << "OutputUHD: GPS Time Lock recovered"; } + num_checks_without_gps_fix = 0; } } else { // Checking the sensor here takes too much // time, it has to be done in a separate thread. if (gpsdo_is_ettus()) { - gps_fix_pt = boost::packaged_task<bool>( - boost::bind(check_gps_locked, m_usrp) ); + gps_fix_future = std::async(std::launch::async, + std::bind(check_gps_locked, m_usrp) ); } else { - gps_fix_pt = boost::packaged_task<bool>( - boost::bind(check_gps_timelock, m_usrp) ); + gps_fix_future = std::async(std::launch::async, + std::bind(check_gps_timelock, m_usrp) ); } - gps_fix_future = gps_fix_pt.get_future(); - - gps_fix_task = boost::thread(boost::move(gps_fix_pt)); } } } diff --git a/src/output/USRPTime.h b/src/output/USRPTime.h index 7527f21..70e55ae 100644 --- a/src/output/USRPTime.h +++ b/src/output/USRPTime.h @@ -42,6 +42,7 @@ DESCRIPTION: #include <memory> #include <string> #include <atomic> +#include <future> #include "Log.h" #include "output/SDR.h" @@ -96,9 +97,7 @@ class USRPTime { using timepoint_t = std::chrono::time_point<std::chrono::steady_clock>; timepoint_t time_last_check; - boost::packaged_task<bool> gps_fix_pt; - boost::unique_future<bool> gps_fix_future; - boost::thread gps_fix_task; + std::future<bool> gps_fix_future; // Returns true if we want to check for the gps_timelock sensor bool gpsfix_needs_check(void) const; |