From 7e1b2a0e3c014bc23aaa7a045efb5f1109818051 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 13 Jul 2011 17:25:40 -0700 Subject: uhd: added tasks to simplify thread spawning use cases --- host/lib/usrp/usrp1/io_impl.cpp | 15 +++++---------- host/lib/usrp/usrp1/soft_time_ctrl.cpp | 29 +++++++---------------------- host/lib/usrp/usrp1/usrp1_impl.hpp | 3 +-- 3 files changed, 13 insertions(+), 34 deletions(-) (limited to 'host/lib/usrp/usrp1') diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index b596bbd04..e81b00d1c 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -24,6 +24,7 @@ #include "usrp_commands.h" #include "usrp1_impl.hpp" #include +#include #include #include #include @@ -131,8 +132,6 @@ struct usrp1_impl::io_impl{ } ~io_impl(void){ - vandal_tribe.interrupt_all(); - vandal_tribe.join_all(); UHD_SAFE_CALL(flush_send_buff();) } @@ -159,7 +158,7 @@ struct usrp1_impl::io_impl{ return omsb.get_new(curr_buff, next_buff); } - boost::thread_group vandal_tribe; + task::sptr vandal_task; boost::system_time last_send_time; }; @@ -230,12 +229,9 @@ void usrp1_impl::io_init(void){ _io_impl = UHD_PIMPL_MAKE(io_impl, (_data_transport)); //create a new vandal thread to poll xerflow conditions - boost::barrier spawn_barrier(2); - _io_impl->vandal_tribe.create_thread(boost::bind( - &usrp1_impl::vandal_conquest_loop, - this, boost::ref(spawn_barrier) + _io_impl->vandal_task = task::make(boost::bind( + &usrp1_impl::vandal_conquest_loop, this )); - spawn_barrier.wait(); //init some handler stuff _io_impl->recv_handler.set_tick_rate(_master_clock_rate); @@ -277,8 +273,7 @@ void usrp1_impl::tx_stream_on_off(bool enb){ * On an overflow, interleave an inline message into recv and print. * This procedure creates "soft" inline and async user messages. */ -void usrp1_impl::vandal_conquest_loop(boost::barrier &spawn_barrier){ - spawn_barrier.wait(); +void usrp1_impl::vandal_conquest_loop(void){ //initialize the async metadata async_metadata_t async_metadata; diff --git a/host/lib/usrp/usrp1/soft_time_ctrl.cpp b/host/lib/usrp/usrp1/soft_time_ctrl.cpp index ac0899e28..78481c3ff 100644 --- a/host/lib/usrp/usrp1/soft_time_ctrl.cpp +++ b/host/lib/usrp/usrp1/soft_time_ctrl.cpp @@ -16,9 +16,8 @@ // #include "soft_time_ctrl.hpp" +#include #include -#include -#include #include #include #include @@ -45,21 +44,12 @@ public: _stream_on_off(stream_on_off) { //synchronously spawn a new thread - boost::barrier spawn_barrier(2); - _thread_group.create_thread(boost::bind( - &soft_time_ctrl_impl::recv_cmd_dispatcher, this, boost::ref(spawn_barrier)) - ); - spawn_barrier.wait(); + _recv_cmd_task = task::make(boost::bind(&soft_time_ctrl_impl::recv_cmd_task, this)); //initialize the time to something this->set_time(time_spec_t(0.0)); } - ~soft_time_ctrl_impl(void){ - _thread_group.interrupt_all(); - _thread_group.join_all(); - } - /******************************************************************* * Time control ******************************************************************/ @@ -204,15 +194,10 @@ public: _stream_mode = cmd.stream_mode; } - void recv_cmd_dispatcher(boost::barrier &spawn_barrier){ - spawn_barrier.wait(); - try{ - boost::shared_ptr cmd; - while (true){ - _cmd_queue.pop_with_wait(cmd); - recv_cmd_handle_cmd(*cmd); - } - } catch(const boost::thread_interrupted &){} + void recv_cmd_task(void){ //task is looped + boost::shared_ptr cmd; + _cmd_queue.pop_with_wait(cmd); + recv_cmd_handle_cmd(*cmd); } bounded_buffer &get_async_queue(void){ @@ -232,7 +217,7 @@ private: bounded_buffer _async_msg_queue; bounded_buffer _inline_msg_queue; const cb_fcn_type _stream_on_off; - boost::thread_group _thread_group; + task::sptr _recv_cmd_task; }; /*********************************************************************** diff --git a/host/lib/usrp/usrp1/usrp1_impl.hpp b/host/lib/usrp/usrp1/usrp1_impl.hpp index cb1497253..1fe0c1784 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.hpp +++ b/host/lib/usrp/usrp1/usrp1_impl.hpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #ifndef INCLUDED_USRP1_IMPL_HPP @@ -130,7 +129,7 @@ private: bool has_rx_halfband(void); bool has_tx_halfband(void); - void vandal_conquest_loop(boost::barrier &); + void vandal_conquest_loop(void); //handle the enables bool _rx_enabled, _tx_enabled; -- cgit v1.2.3