mirror of
https://github.com/fairwaves/UHD-Fairwaves.git
synced 2025-10-22 23:31:59 +00:00
umtrx_cal_*: fix for abrupt termination
tx_thread creates a child thread, which it join()s on, when terminating calling interrupt() on tx_thread interferes with the join() so we replace interrupt() with an atomic flag (not sure how this worked before)
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "usrp_cal_utils.hpp"
|
||||
#include <uhd/utils/safe_main.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
@@ -342,8 +343,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
|
||||
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
|
||||
|
||||
//create a transmitter thread
|
||||
std::atomic<bool> interrupted(false);
|
||||
boost::thread_group threads;
|
||||
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
|
||||
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl, boost::ref(interrupted)));
|
||||
|
||||
//store the results here
|
||||
std::vector<result_t> results;
|
||||
@@ -403,7 +405,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
|
||||
std::cout << std::endl;
|
||||
|
||||
//stop the transmitter
|
||||
threads.interrupt_all();
|
||||
interrupted = true;
|
||||
threads.join_all();
|
||||
|
||||
if (not vm.count("single_test"))
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "usrp_cal_utils.hpp"
|
||||
#include <uhd/utils/safe_main.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/math/special_functions/round.hpp>
|
||||
#include <iostream>
|
||||
@@ -83,8 +84,9 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
|
||||
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
|
||||
|
||||
//create a transmitter thread
|
||||
std::atomic<bool> interrupted(false);
|
||||
boost::thread_group threads;
|
||||
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl));
|
||||
threads.create_thread(boost::bind(&tx_thread, usrp, tx_wave_freq, tx_wave_ampl, boost::ref(interrupted)));
|
||||
|
||||
//re-usable buffer for samples
|
||||
std::vector<samp_type> buff;
|
||||
@@ -177,7 +179,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
|
||||
std::cout << std::endl;
|
||||
|
||||
//stop the transmitter
|
||||
threads.interrupt_all();
|
||||
interrupted = true;
|
||||
threads.join_all();
|
||||
|
||||
store_results(usrp, results, "tx", "iq", vm.count("append"));
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#include <complex>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <atomic>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
@@ -227,7 +228,7 @@ static void capture_samples(
|
||||
/***********************************************************************
|
||||
* Transmit thread
|
||||
**********************************************************************/
|
||||
static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_freq, const double tx_wave_ampl){
|
||||
static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_freq, const double tx_wave_ampl, std::atomic<bool> &interrupted){
|
||||
uhd::set_thread_priority_safe();
|
||||
|
||||
//create a transmit streamer
|
||||
@@ -246,7 +247,7 @@ static void tx_thread(uhd::usrp::multi_usrp::sptr usrp, const double tx_wave_fre
|
||||
wave_table table(tx_wave_ampl);
|
||||
|
||||
//fill buff and send until interrupted
|
||||
while (not boost::this_thread::interruption_requested()){
|
||||
while (not interrupted){
|
||||
for (size_t i = 0; i < buff.size(); i++){
|
||||
buff[i] = table(index += step);
|
||||
}
|
||||
|
Reference in New Issue
Block a user