mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-19 05:33:02 +00:00
Make use of start() and stop() in pcps_acquisition_cc
This is a more natural place to start and stop threads in gnuradio blocks
This commit is contained in:
parent
ba3d7bfcd8
commit
94f0df8ebe
@ -136,9 +136,6 @@ pcps_acquisition_cc::pcps_acquisition_cc(
|
|||||||
d_worker_active = false;
|
d_worker_active = false;
|
||||||
d_data_buffer = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
|
d_data_buffer = static_cast<gr_complex*>(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment()));
|
||||||
|
|
||||||
// Start the worker thread and wait for it to acknowledge:
|
|
||||||
std::thread t1( &pcps_acquisition_cc::acquisition_core, this );
|
|
||||||
std::swap( d_worker_thread, t1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -165,13 +162,17 @@ pcps_acquisition_cc::~pcps_acquisition_cc()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Let the worker thread know that we are done and then wait to join
|
// Let the worker thread know that we are done and then wait to join
|
||||||
|
if( d_worker_thread.joinable() )
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lk( d_mutex );
|
{
|
||||||
d_done = true;
|
std::lock_guard<std::mutex> lk( d_mutex );
|
||||||
d_cond.notify_one();
|
d_done = true;
|
||||||
|
d_cond.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
d_worker_thread.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
d_worker_thread.join();
|
|
||||||
volk_gnsssdr_free( d_data_buffer );
|
volk_gnsssdr_free( d_data_buffer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,3 +555,31 @@ void pcps_acquisition_cc::acquisition_core( void )
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pcps_acquisition_cc::start( void )
|
||||||
|
{
|
||||||
|
d_worker_active = false;
|
||||||
|
d_done = false;
|
||||||
|
|
||||||
|
// Start the worker thread and wait for it to acknowledge:
|
||||||
|
d_worker_thread = std::move( std::thread( &pcps_acquisition_cc::acquisition_core, this ) );
|
||||||
|
|
||||||
|
return gr::block::start();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pcps_acquisition_cc::stop( void )
|
||||||
|
{
|
||||||
|
// Let the worker thread know that we are done and then wait to join
|
||||||
|
if( d_worker_thread.joinable() )
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk( d_mutex );
|
||||||
|
d_done = true;
|
||||||
|
d_cond.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
d_worker_thread.join();
|
||||||
|
}
|
||||||
|
return gr::block::stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -249,6 +249,16 @@ public:
|
|||||||
int general_work(int noutput_items, gr_vector_int &ninput_items,
|
int general_work(int noutput_items, gr_vector_int &ninput_items,
|
||||||
gr_vector_const_void_star &input_items,
|
gr_vector_const_void_star &input_items,
|
||||||
gr_vector_void_star &output_items);
|
gr_vector_void_star &output_items);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Called by the flowgraph when processing is about to start.
|
||||||
|
*/
|
||||||
|
bool start( void );
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Called by the flowgraph when processing is done.
|
||||||
|
*/
|
||||||
|
bool stop( void );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* GNSS_SDR_PCPS_ACQUISITION_CC_H_*/
|
#endif /* GNSS_SDR_PCPS_ACQUISITION_CC_H_*/
|
||||||
|
Loading…
Reference in New Issue
Block a user