From e7dc926dad3b4cc11435c833f13408833e2df703 Mon Sep 17 00:00:00 2001 From: Javier Arribas Date: Tue, 16 Jul 2019 11:07:02 +0200 Subject: [PATCH] Improving the concurrent queue and fix missing dependencies --- src/algorithms/PVT/libs/rtcm.cc | 1 + src/algorithms/PVT/libs/rtcm.h | 1 + src/algorithms/PVT/libs/rtcm_printer.cc | 1 + src/core/receiver/concurrent_queue.h | 32 +++++++++++++++++++------ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/algorithms/PVT/libs/rtcm.cc b/src/algorithms/PVT/libs/rtcm.cc index 0cad7ec65..da186273f 100644 --- a/src/algorithms/PVT/libs/rtcm.cc +++ b/src/algorithms/PVT/libs/rtcm.cc @@ -38,6 +38,7 @@ #include #include #include +#include #include // for std::reverse #include // std::chrono::seconds #include // for std::fmod diff --git a/src/algorithms/PVT/libs/rtcm.h b/src/algorithms/PVT/libs/rtcm.h index 5f0c7a8cb..26635b5b3 100644 --- a/src/algorithms/PVT/libs/rtcm.h +++ b/src/algorithms/PVT/libs/rtcm.h @@ -55,6 +55,7 @@ #include #include #include +#include #if BOOST_GREATER_1_65 using b_io_context = boost::asio::io_context; diff --git a/src/algorithms/PVT/libs/rtcm_printer.cc b/src/algorithms/PVT/libs/rtcm_printer.cc index d30959017..7526cbb78 100644 --- a/src/algorithms/PVT/libs/rtcm_printer.cc +++ b/src/algorithms/PVT/libs/rtcm_printer.cc @@ -46,6 +46,7 @@ #include // for cout, cerr #include // for tcgetattr #include // for close, write +#include #if HAS_STD_FILESYSTEM #include diff --git a/src/core/receiver/concurrent_queue.h b/src/core/receiver/concurrent_queue.h index 66cefbf96..da223d16c 100644 --- a/src/core/receiver/concurrent_queue.h +++ b/src/core/receiver/concurrent_queue.h @@ -31,7 +31,9 @@ #ifndef GNSS_SDR_CONCURRENT_QUEUE_H #define GNSS_SDR_CONCURRENT_QUEUE_H -#include +#include +#include +#include #include template @@ -48,7 +50,7 @@ class Concurrent_Queue public: void push(Data const& data) { - boost::mutex::scoped_lock lock(the_mutex); + std::unique_lock lock(the_mutex); the_queue.push(data); lock.unlock(); the_condition_variable.notify_one(); @@ -56,13 +58,13 @@ public: bool empty() const { - boost::mutex::scoped_lock lock(the_mutex); + std::unique_lock lock(the_mutex); return the_queue.empty(); } bool try_pop(Data& popped_value) { - boost::mutex::scoped_lock lock(the_mutex); + std::unique_lock lock(the_mutex); if (the_queue.empty()) { return false; @@ -74,7 +76,7 @@ public: void wait_and_pop(Data& popped_value) { - boost::mutex::scoped_lock lock(the_mutex); + std::unique_lock lock(the_mutex); while (the_queue.empty()) { the_condition_variable.wait(lock); @@ -83,9 +85,25 @@ public: the_queue.pop(); } + bool timed_wait_and_pop(Data& popped_value, int wait_ms) + { + std::unique_lock lock(the_mutex); + if (the_queue.empty()) + { + the_condition_variable.wait_for(lock,std::chrono::milliseconds(wait_ms)); + if (the_queue.empty()) + { + return false; + } + } + popped_value = the_queue.front(); + the_queue.pop(); + return true; + } + private: std::queue the_queue; - mutable boost::mutex the_mutex; - boost::condition_variable the_condition_variable; + mutable std::mutex the_mutex; + std::condition_variable the_condition_variable; }; #endif