From ad5690c52fffd2d9a03f4c97f8a114f488f95a11 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 12 Nov 2020 15:24:15 +0100 Subject: [PATCH] Fix exit with enter+q when Acquisition_XX.blocking=false --- .../acquisition/gnuradio_blocks/CMakeLists.txt | 1 + .../acquisition/gnuradio_blocks/pcps_acquisition.cc | 9 ++++++++- .../acquisition/gnuradio_blocks/pcps_acquisition.h | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt index cdc89e2eb..64ca69764 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt @@ -75,6 +75,7 @@ target_link_libraries(acquisition_gr_blocks Armadillo::armadillo Gnuradio::runtime Gnuradio::fft + Threads::Threads Volk::volk Volkgnsssdr::volkgnsssdr PRIVATE diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc index 78df6b841..759228cf6 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc @@ -930,6 +930,11 @@ int pcps_acquisition::general_work(int noutput_items __attribute__((unused)), * 6. Declare positive or negative acquisition using a message port */ gr::thread::scoped_lock lk(d_setlock); + if (!d_active and d_worker_active and !d_acq_parameters.blocking) + { + pthread_cancel(d_id_worker); + return 0; + } if (!d_active or d_worker_active) { if (!d_acq_parameters.blocking_on_standby) @@ -1016,7 +1021,9 @@ int pcps_acquisition::general_work(int noutput_items __attribute__((unused)), } else { - gr::thread::thread d_worker(&pcps_acquisition::acquisition_core, this, d_sample_counter); + d_worker = std::thread([&] { pcps_acquisition::acquisition_core(d_sample_counter); }); + d_id_worker = d_worker.native_handle(); + d_worker.detach(); d_worker_active = true; } consume_each(0); diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h index fedd18d18..bcdcf5332 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h @@ -59,10 +59,11 @@ #include #include #include +#include #include #include +#include #include - #if HAS_STD_SPAN #include namespace own = std; @@ -259,6 +260,8 @@ private: arma::fmat d_narrow_grid; std::string d_dump_filename; + std::thread d_worker; + pthread_t d_id_worker; int64_t d_dump_number; uint64_t d_sample_counter;