diff options
author | Josh Blum <josh@joshknows.com> | 2011-03-10 14:37:34 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-03-10 14:37:34 -0800 |
commit | 09149bbf7d28f67e68d65f7ba153ccd31ae48e5b (patch) | |
tree | 93e2be732f3d5ca2e0eb2b3d528b08ccea97c6a3 /host/lib | |
parent | 0336db128e38bd99d69e192189a63ba6d3d3e36b (diff) | |
download | uhd-09149bbf7d28f67e68d65f7ba153ccd31ae48e5b.tar.gz uhd-09149bbf7d28f67e68d65f7ba153ccd31ae48e5b.tar.bz2 uhd-09149bbf7d28f67e68d65f7ba153ccd31ae48e5b.zip |
usrp1: safe destruction for usrp1 device
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/transport/libusb1_zero_copy.cpp | 13 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/io_impl.cpp | 3 | ||||
-rw-r--r-- | host/lib/usrp/usrp1/usrp1_impl.cpp | 12 |
3 files changed, 20 insertions, 8 deletions
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp index 1b6712871..6dee69711 100644 --- a/host/lib/transport/libusb1_zero_copy.cpp +++ b/host/lib/transport/libusb1_zero_copy.cpp @@ -33,6 +33,11 @@ using namespace uhd::transport; static const size_t DEFAULT_NUM_XFERS = 16; //num xfers static const size_t DEFAULT_XFER_SIZE = 32*512; //bytes +//! helper function: handles all async callbacks +static void libusb_async_cb(libusb_transfer *lut){ + (*static_cast<boost::function<void()> *>(lut->user_data))(); +} + /*********************************************************************** * Reusable managed receiver buffer: * - Associated with a particular libusb transfer struct. @@ -79,7 +84,8 @@ public: void commit(size_t len){ if (_expired) return; _lut->length = len; - UHD_ASSERT_THROW(libusb_submit_transfer(_lut) == 0); + if(len == 0) libusb_async_cb(_lut); + else UHD_ASSERT_THROW(libusb_submit_transfer(_lut) == 0); _expired = true; } @@ -100,11 +106,6 @@ private: bool _expired; }; -//! helper function: handles all async callbacks -static void libusb_async_cb(libusb_transfer *lut){ - (*static_cast<boost::function<void()> *>(lut->user_data))(); -} - /*********************************************************************** * USB zero_copy device class **********************************************************************/ diff --git a/host/lib/usrp/usrp1/io_impl.cpp b/host/lib/usrp/usrp1/io_impl.cpp index 8beeccf8f..b3268298e 100644 --- a/host/lib/usrp/usrp1/io_impl.cpp +++ b/host/lib/usrp/usrp1/io_impl.cpp @@ -18,6 +18,7 @@ #include "../../transport/vrt_packet_handler.hpp" #include "usrp_commands.h" #include "usrp1_impl.hpp" +#include <uhd/utils/safe_call.hpp> #include <uhd/utils/thread_priority.hpp> #include <uhd/transport/bounded_buffer.hpp> #include <boost/bind.hpp> @@ -114,7 +115,7 @@ struct usrp1_impl::io_impl{ } ~io_impl(void){ - flush_send_buff(); + UHD_SAFE_CALL(flush_send_buff();) } zero_copy_if::sptr data_transport; diff --git a/host/lib/usrp/usrp1/usrp1_impl.cpp b/host/lib/usrp/usrp1/usrp1_impl.cpp index caea7c043..7005c59f2 100644 --- a/host/lib/usrp/usrp1/usrp1_impl.cpp +++ b/host/lib/usrp/usrp1/usrp1_impl.cpp @@ -19,6 +19,7 @@ #include "usrp1_ctrl.hpp" #include "fpga_regs_standard.h" #include "usrp_spi_defs.h" +#include <uhd/utils/safe_call.hpp> #include <uhd/transport/usb_control.hpp> #include <uhd/usrp/device_props.hpp> #include <uhd/usrp/mboard_props.hpp> @@ -199,7 +200,16 @@ usrp1_impl::usrp1_impl(uhd::transport::usb_zero_copy::sptr data_transport, } usrp1_impl::~usrp1_impl(void){ - /* NOP */ + //Safely destruct all RAII objects in a device. + //This prevents the mboard deconstructor from throwing, + //which allows the device to be safely deconstructed. + BOOST_FOREACH(dboard_slot_t slot, _dboard_slots){ + UHD_SAFE_CALL(_dboard_managers[slot].reset();) + UHD_SAFE_CALL(_dboard_ifaces[slot].reset();) + UHD_SAFE_CALL(_codec_ctrls[slot].reset();) + } + UHD_SAFE_CALL(_clock_ctrl.reset();) + UHD_SAFE_CALL(_io_impl.reset();) } bool usrp1_impl::recv_async_msg(uhd::async_metadata_t &, double timeout){ |