From 1c5076ea68345e74de35cad43e4a4b4adf68fa15 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 31 Mar 2011 15:00:56 -0700 Subject: uhd: implemented boost barriers on all code that creates threads The barrier ensures that the thread must spawn before the caller exits. Some of the code already used a mutex to accomplish this, however cygwin chokes when a mutex is locked twice by the same thread. Mutex implementations were replaced with the barrier implementation. Also the barrier implementation is far cleaner. --- host/lib/usrp/usrp_e100/io_impl.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'host/lib/usrp/usrp_e100/io_impl.cpp') diff --git a/host/lib/usrp/usrp_e100/io_impl.cpp b/host/lib/usrp/usrp_e100/io_impl.cpp index fc6aaeaee..cbab5a761 100644 --- a/host/lib/usrp/usrp_e100/io_impl.cpp +++ b/host/lib/usrp/usrp_e100/io_impl.cpp @@ -23,7 +23,8 @@ #include "../../transport/vrt_packet_handler.hpp" #include #include -#include +#include +#include #include using namespace uhd; @@ -93,7 +94,7 @@ struct usrp_e100_impl::io_impl{ bool continuous_streaming; //a pirate's life is the life for me! - void recv_pirate_loop(usrp_e100_clock_ctrl::sptr); + void recv_pirate_loop(boost::barrier &, usrp_e100_clock_ctrl::sptr); bounded_buffer recv_pirate_booty; bounded_buffer async_msg_fifo; boost::thread_group recv_pirate_crew; @@ -105,8 +106,10 @@ struct usrp_e100_impl::io_impl{ * - while raiding, loot for recv buffers * - put booty into the alignment buffer **********************************************************************/ -void usrp_e100_impl::io_impl::recv_pirate_loop(usrp_e100_clock_ctrl::sptr clock_ctrl) -{ +void usrp_e100_impl::io_impl::recv_pirate_loop( + boost::barrier &spawn_barrier, usrp_e100_clock_ctrl::sptr clock_ctrl +){ + spawn_barrier.wait(); set_thread_priority_safe(); recv_pirate_crew_raiding = true; @@ -201,9 +204,12 @@ void usrp_e100_impl::io_init(void){ _iface->poke32(UE_REG_CTRL_TX_POLICY, UE_FLAG_CTRL_TX_POLICY_NEXT_PACKET); //spawn a pirate, yarrr! + boost::barrier spawn_barrier(2); _io_impl->recv_pirate_crew.create_thread(boost::bind( - &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), _clock_ctrl + &usrp_e100_impl::io_impl::recv_pirate_loop, _io_impl.get(), + boost::ref(spawn_barrier), _clock_ctrl )); + spawn_barrier.wait(); } void usrp_e100_impl::issue_stream_cmd(const stream_cmd_t &stream_cmd){ -- cgit v1.2.3