From c5ddbfe33759dd80447c45513a05a4755797b05a Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 10 Apr 2018 22:23:50 +0200 Subject: Replace boost in output/Feedback --- src/output/Feedback.cpp | 28 +++++++++++++--------------- src/output/Feedback.h | 12 +++++++----- 2 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src/output') diff --git a/src/output/Feedback.cpp b/src/output/Feedback.cpp index 97d6e04..f9c1af1 100644 --- a/src/output/Feedback.cpp +++ b/src/output/Feedback.cpp @@ -40,7 +40,6 @@ DESCRIPTION: #include #include #include -#include #include "output/Feedback.h" #include "Utils.h" #include "Socket.h" @@ -60,10 +59,10 @@ DPDFeedbackServer::DPDFeedbackServer( if (m_port) { m_running.store(true); - rx_burst_thread = boost::thread( + rx_burst_thread = std::thread( &DPDFeedbackServer::ReceiveBurstThread, this); - burst_tcp_thread = boost::thread( + burst_tcp_thread = std::thread( &DPDFeedbackServer::ServeFeedbackThread, this); } } @@ -72,12 +71,12 @@ DPDFeedbackServer::~DPDFeedbackServer() { m_running.store(false); - rx_burst_thread.interrupt(); + burstRequest.mutex_notification.notify_all(); + if (rx_burst_thread.joinable()) { rx_burst_thread.join(); } - burst_tcp_thread.interrupt(); if (burst_tcp_thread.joinable()) { burst_tcp_thread.join(); } @@ -91,7 +90,7 @@ void DPDFeedbackServer::set_tx_frame( throw runtime_error("DPDFeedbackServer not running"); } - boost::mutex::scoped_lock lock(burstRequest.mutex); + unique_lock lock(burstRequest.mutex); if (buf.size() % sizeof(complexf) != 0) { throw logic_error("Buffer for tx frame has incorrect size"); @@ -137,7 +136,7 @@ void DPDFeedbackServer::ReceiveBurstThread() set_thread_name("dpdreceiveburst"); while (m_running) { - boost::mutex::scoped_lock lock(burstRequest.mutex); + unique_lock lock(burstRequest.mutex); while (burstRequest.state != BurstRequestState::SaveReceiveFrame) { if (not m_running) break; burstRequest.mutex_notification.wait(lock); @@ -192,9 +191,6 @@ void DPDFeedbackServer::ReceiveBurstThread() catch (const std::exception &e) { etiLog.level(error) << "DPD Feedback RX exception: " << e.what(); } - catch (const boost::thread_interrupted& e) { - etiLog.level(info) << "DPD Feedback RX stopping."; - } catch (...) { etiLog.level(error) << "DPD Feedback RX unknown exception!"; } @@ -213,6 +209,10 @@ void DPDFeedbackServer::ServeFeedback() struct sockaddr_in client; TCPSocket client_sock = m_server_sock.accept_with_timeout(1000, &client); + if (not m_running) { + break; + } + if (not client_sock.valid()) { // No connection request received continue; @@ -243,15 +243,13 @@ void DPDFeedbackServer::ServeFeedback() // We are ready to issue the request now { - boost::mutex::scoped_lock lock(burstRequest.mutex); + unique_lock lock(burstRequest.mutex); burstRequest.num_samples = num_samples; burstRequest.state = BurstRequestState::SaveTransmitFrame; - - lock.unlock(); } // Wait for the result to be ready - boost::mutex::scoped_lock lock(burstRequest.mutex); + unique_lock lock(burstRequest.mutex); while (burstRequest.state != BurstRequestState::Acquired) { if (not m_running) break; burstRequest.mutex_notification.wait(lock); @@ -350,7 +348,7 @@ void DPDFeedbackServer::ServeFeedbackThread() etiLog.level(error) << "DPD Feedback Server unknown exception!"; } - boost::this_thread::sleep(boost::posix_time::seconds(5)); + this_thread::sleep_for(chrono::seconds(5)); } m_running.store(false); diff --git a/src/output/Feedback.h b/src/output/Feedback.h index 2cad508..aef86b0 100644 --- a/src/output/Feedback.h +++ b/src/output/Feedback.h @@ -36,7 +36,9 @@ DESCRIPTION: # include #endif -#include +#include +#include +#include #include #include #include @@ -56,8 +58,8 @@ enum class BurstRequestState { struct FeedbackBurstRequest { // All fields in this struct are protected - mutable boost::mutex mutex; - boost::condition_variable mutex_notification; + mutable std::mutex mutex; + std::condition_variable mutex_notification; BurstRequestState state = BurstRequestState::None; @@ -102,8 +104,8 @@ class DPDFeedbackServer { void ServeFeedbackThread(void); void ServeFeedback(void); - boost::thread rx_burst_thread; - boost::thread burst_tcp_thread; + std::thread rx_burst_thread; + std::thread burst_tcp_thread; FeedbackBurstRequest burstRequest; -- cgit v1.2.3