aboutsummaryrefslogtreecommitdiffstats
path: root/host/lib/usrp/usrp2/io_impl.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-07-13 17:25:40 -0700
committerJosh Blum <josh@joshknows.com>2011-07-13 17:25:40 -0700
commit7e1b2a0e3c014bc23aaa7a045efb5f1109818051 (patch)
tree748f2f0cb78d133a478f61a14b7a18a4de560673 /host/lib/usrp/usrp2/io_impl.cpp
parent9d470d5db39c75308f3ac15a8512f08b714b4ee4 (diff)
downloaduhd-7e1b2a0e3c014bc23aaa7a045efb5f1109818051.tar.gz
uhd-7e1b2a0e3c014bc23aaa7a045efb5f1109818051.tar.bz2
uhd-7e1b2a0e3c014bc23aaa7a045efb5f1109818051.zip
uhd: added tasks to simplify thread spawning use cases
Diffstat (limited to 'host/lib/usrp/usrp2/io_impl.cpp')
-rw-r--r--host/lib/usrp/usrp2/io_impl.cpp29
1 files changed, 9 insertions, 20 deletions
diff --git a/host/lib/usrp/usrp2/io_impl.cpp b/host/lib/usrp/usrp2/io_impl.cpp
index 4c55012ce..7028e1ff8 100644
--- a/host/lib/usrp/usrp2/io_impl.cpp
+++ b/host/lib/usrp/usrp2/io_impl.cpp
@@ -22,15 +22,15 @@
#include "usrp2_regs.hpp"
#include <uhd/utils/log.hpp>
#include <uhd/utils/msg.hpp>
+#include <uhd/utils/tasks.hpp>
#include <uhd/exception.hpp>
#include <uhd/utils/byteswap.hpp>
#include <uhd/utils/thread_priority.hpp>
#include <uhd/transport/bounded_buffer.hpp>
+#include <boost/thread/thread.hpp>
#include <boost/format.hpp>
#include <boost/bind.hpp>
#include <boost/thread/mutex.hpp>
-#include <boost/thread/thread.hpp>
-#include <boost/thread/barrier.hpp>
#include <iostream>
using namespace uhd;
@@ -134,11 +134,6 @@ struct usrp2_impl::io_impl{
/* NOP */
}
- ~io_impl(void){
- recv_pirate_crew.interrupt_all();
- recv_pirate_crew.join_all();
- }
-
managed_send_buffer::sptr get_send_buff(size_t chan, double timeout){
flow_control_monitor &fc_mon = *fc_mons[chan];
@@ -163,8 +158,8 @@ struct usrp2_impl::io_impl{
sph::send_packet_handler send_handler;
//methods and variables for the pirate crew
- void recv_pirate_loop(boost::barrier &, zero_copy_if::sptr, size_t);
- boost::thread_group recv_pirate_crew;
+ void recv_pirate_loop(zero_copy_if::sptr, size_t);
+ std::list<task::sptr> pirate_tasks;
bounded_buffer<async_metadata_t> async_msg_fifo;
double tick_rate;
};
@@ -176,11 +171,8 @@ struct usrp2_impl::io_impl{
* - put async message packets into queue
**********************************************************************/
void usrp2_impl::io_impl::recv_pirate_loop(
- boost::barrier &spawn_barrier,
- zero_copy_if::sptr err_xport,
- size_t index
+ zero_copy_if::sptr err_xport, size_t index
){
- spawn_barrier.wait();
set_thread_priority_safe();
//store a reference to the flow control monitor (offset by max dsps)
@@ -231,7 +223,7 @@ void usrp2_impl::io_impl::recv_pirate_loop(
//TODO unknown received packet, may want to print error...
}
}catch(const std::exception &e){
- UHD_MSG(error) << "Error (usrp2 recv pirate loop): " << e.what() << std::endl;
+ UHD_MSG(error) << "Error in recv pirate loop: " << e.what() << std::endl;
}
}
}
@@ -264,17 +256,14 @@ void usrp2_impl::io_init(void){
}
//create a new pirate thread for each zc if (yarr!!)
- boost::barrier spawn_barrier(_mbc.size()+1);
size_t index = 0;
BOOST_FOREACH(const std::string &mb, _mbc.keys()){
//spawn a new pirate to plunder the recv booty
- _io_impl->recv_pirate_crew.create_thread(boost::bind(
- &usrp2_impl::io_impl::recv_pirate_loop,
- _io_impl.get(), boost::ref(spawn_barrier),
+ _io_impl->pirate_tasks.push_back(task::make(boost::bind(
+ &usrp2_impl::io_impl::recv_pirate_loop, _io_impl.get(),
_mbc[mb].err_xports.at(0), index++
- ));
+ )));
}
- spawn_barrier.wait();
//init some handler stuff
_io_impl->recv_handler.set_vrt_unpacker(&vrt::if_hdr_unpack_be);