1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 04:00:34 +00:00

Improving the concurrent queue and fix missing dependencies

This commit is contained in:
Javier Arribas 2019-07-16 11:07:02 +02:00
parent c36cb0cf4b
commit e7dc926dad
4 changed files with 28 additions and 7 deletions

View File

@ -38,6 +38,7 @@
#include <boost/crc.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/dynamic_bitset.hpp>
#include <boost/exception/diagnostic_information.hpp>
#include <algorithm> // for std::reverse
#include <chrono> // std::chrono::seconds
#include <cmath> // for std::fmod

View File

@ -55,6 +55,7 @@
#include <thread>
#include <utility>
#include <vector>
#include <list>
#if BOOST_GREATER_1_65
using b_io_context = boost::asio::io_context;

View File

@ -46,6 +46,7 @@
#include <iostream> // for cout, cerr
#include <termios.h> // for tcgetattr
#include <unistd.h> // for close, write
#include <boost/exception/diagnostic_information.hpp>
#if HAS_STD_FILESYSTEM
#include <system_error>

View File

@ -31,7 +31,9 @@
#ifndef GNSS_SDR_CONCURRENT_QUEUE_H
#define GNSS_SDR_CONCURRENT_QUEUE_H
#include <boost/thread.hpp>
#include <mutex>
#include <thread>
#include <chrono>
#include <queue>
template <typename Data>
@ -48,7 +50,7 @@ class Concurrent_Queue
public:
void push(Data const& data)
{
boost::mutex::scoped_lock lock(the_mutex);
std::unique_lock<std::mutex> 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<std::mutex> lock(the_mutex);
return the_queue.empty();
}
bool try_pop(Data& popped_value)
{
boost::mutex::scoped_lock lock(the_mutex);
std::unique_lock<std::mutex> 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<std::mutex> 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<std::mutex> 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<Data> 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