1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-31 11:19:18 +00:00

Use lambda instead of boost::bind

This commit is contained in:
Carles Fernandez 2020-04-26 09:10:53 +02:00
parent 420db2dfd6
commit 873b1feb68
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 61 additions and 12 deletions

View File

@ -103,6 +103,21 @@ if(Boost_VERSION_STRING VERSION_GREATER 1.65.99)
)
endif()
if(CMAKE_VERSION VERSION_GREATER 3.1)
set(has_generic_lambdas HAS_GENERIC_LAMBDA=1)
set(no_has_generic_lambdas HAS_GENERIC_LAMBDA=0)
target_compile_definitions(signal_source_gr_blocks
PRIVATE
"$<$<COMPILE_FEATURES:cxx_generic_lambdas>:${has_generic_lambdas}>"
"$<$<NOT:$<COMPILE_FEATURES:cxx_generic_lambdas>>:${no_has_generic_lambdas}>"
)
else()
target_compile_definitions(signal_source_gr_blocks
PRIVATE
-DHAS_GENERIC_LAMBDA=0
)
endif()
if(ENABLE_CLANG_TIDY)
if(CLANG_TIDY_EXE)
set_target_properties(signal_source_gr_blocks

View File

@ -24,6 +24,10 @@
#include <array>
#include <cstdint>
#include <utility>
#if HAS_GENERIC_LAMBDA
#else
#include <boost/bind.hpp>
#endif
const int FIFO_SIZE = 1472000;
@ -148,7 +152,12 @@ bool Gr_Complex_Ip_Packet_Source::start()
if (open() == true)
{
// start pcap capture thread
d_pcap_thread = new boost::thread(boost::bind(&Gr_Complex_Ip_Packet_Source::my_pcap_loop_thread, this, descr));
d_pcap_thread = new boost::thread(
#if HAS_GENERIC_LAMBDA
[this] { my_pcap_loop_thread(descr); });
#else
boost::bind(&Gr_Complex_Ip_Packet_Source::my_pcap_loop_thread, this, descr));
#endif
return true;
}
return false;

View File

@ -24,6 +24,10 @@
#include <boost/thread/thread.hpp>
#include <glog/logging.h>
#include <map>
#if HAS_GENERIC_LAMBDA
#else
#include <boost/bind.hpp>
#endif
namespace ip = boost::asio::ip;
@ -134,9 +138,18 @@ rtl_tcp_signal_source_c::rtl_tcp_signal_source_c(const std::string &address,
// 6. Start reading
boost::asio::async_read(socket_, boost::asio::buffer(data_),
#if HAS_GENERIC_LAMBDA
[this](auto &&PH1, auto &&PH2) { handle_read(PH1, PH2); });
#else
boost::bind(&rtl_tcp_signal_source_c::handle_read,
this, _1, _2));
boost::thread(boost::bind(&b_io_context::run, &io_context_));
#endif
boost::thread(
#if HAS_GENERIC_LAMBDA
[ObjectPtr = &io_context_] { ObjectPtr->run(); });
#else
boost::bind(&b_io_context::run, &io_context_));
#endif
}
@ -288,8 +301,11 @@ void rtl_tcp_signal_source_c::handle_read(const boost::system::error_code &ec,
// Unpack read data
boost::mutex::scoped_lock lock(mutex_);
not_full_.wait(lock,
boost::bind(&rtl_tcp_signal_source_c::not_full,
this));
#if HAS_GENERIC_LAMBDA
[this] { not_full(); });
#else
boost::bind(&rtl_tcp_signal_source_c::not_full, this));
#endif
for (size_t i = 0; i < bytes_transferred; i++)
{
@ -299,8 +315,11 @@ void rtl_tcp_signal_source_c::handle_read(const boost::system::error_code &ec,
// wait until there's space for more
not_empty_.notify_one(); // needed?
not_full_.wait(lock,
boost::bind(&rtl_tcp_signal_source_c::not_full,
this));
#if HAS_GENERIC_LAMBDA
[this] { not_full(); });
#else
boost::bind(&rtl_tcp_signal_source_c::not_full, this));
#endif
}
buffer_.push_front(lookup_[data_[i]]);
@ -312,8 +331,11 @@ void rtl_tcp_signal_source_c::handle_read(const boost::system::error_code &ec,
// Read some more
boost::asio::async_read(socket_,
boost::asio::buffer(data_),
boost::bind(&rtl_tcp_signal_source_c::handle_read,
this, _1, _2));
#if HAS_GENERIC_LAMBDA
[this](auto &&PH1, auto &&PH2) { handle_read(PH1, PH2); });
#else
boost::bind(&rtl_tcp_signal_source_c::handle_read, this, _1, _2));
#endif
}
}
@ -331,9 +353,12 @@ int rtl_tcp_signal_source_c::work(int noutput_items,
{
boost::mutex::scoped_lock lock(mutex_);
not_empty_.wait(lock, boost::bind(&rtl_tcp_signal_source_c::not_empty,
this));
not_empty_.wait(lock,
#if HAS_GENERIC_LAMBDA
[this] { not_empty(); });
#else
boost::bind(&rtl_tcp_signal_source_c::not_empty, this));
#endif
for (; i < noutput_items && unread_ > 1; i++)
{
float re = buffer_[--unread_];

View File

@ -158,7 +158,7 @@ AcqPerfTest_msg_rx::AcqPerfTest_msg_rx(Concurrent_Queue<int>& queue) : gr::block
{
this->message_port_register_in(pmt::mp("events"));
this->set_msg_handler(pmt::mp("events"),
#if HAS_GENNERIC_LAMBDA
#if HAS_GENERIC_LAMBDA
[this](auto&& PH1) { msg_handler_events(PH1); });
#else
boost::bind(&AcqPerfTest_msg_rx::msg_handler_events, this, _1));