summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-03-17 14:32:12 -0700
committerJosh Blum <josh@joshknows.com>2011-03-17 14:32:12 -0700
commitfc6280dffd7f188d9d2718236a959eedc30c8a36 (patch)
treebf62e58be1605fb729916f45efab131654042ba9 /host
parentdd1571aa2369573e8f4626b078fbd794e84904cd (diff)
parent9d752805de2020b6a8705c4abfce536620dcb760 (diff)
downloaduhd-fc6280dffd7f188d9d2718236a959eedc30c8a36.tar.gz
uhd-fc6280dffd7f188d9d2718236a959eedc30c8a36.tar.bz2
uhd-fc6280dffd7f188d9d2718236a959eedc30c8a36.zip
Merge branch 'usb-cancel' into next
Conflicts: host/lib/transport/libusb1_zero_copy.cpp
Diffstat (limited to 'host')
-rw-r--r--host/lib/transport/libusb1_zero_copy.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/host/lib/transport/libusb1_zero_copy.cpp b/host/lib/transport/libusb1_zero_copy.cpp
index 6dee69711..697944089 100644
--- a/host/lib/transport/libusb1_zero_copy.cpp
+++ b/host/lib/transport/libusb1_zero_copy.cpp
@@ -38,6 +38,12 @@ static void libusb_async_cb(libusb_transfer *lut){
(*static_cast<boost::function<void()> *>(lut->user_data))();
}
+//! callback to free transfer upon cancellation
+static void cancel_transfer_cb(libusb_transfer *lut){
+ if (lut->status == LIBUSB_TRANSFER_CANCELLED) libusb_free_transfer(lut);
+ else std::cout << "libusb cancel_transfer unexpected status " << lut->status << std::endl;
+}
+
/***********************************************************************
* Reusable managed receiver buffer:
* - Associated with a particular libusb transfer struct.
@@ -191,16 +197,18 @@ public:
}
~libusb_zero_copy_impl(void){
- //shutdown the threads
- _threads_running = false;
- _thread_group.interrupt_all();
- _thread_group.join_all();
-
//cancel and free all transfers
BOOST_FOREACH(libusb_transfer *lut, _all_luts){
+ lut->callback = &cancel_transfer_cb;
libusb_cancel_transfer(lut);
- libusb_free_transfer(lut);
+ while(lut->status != LIBUSB_TRANSFER_CANCELLED && lut->status != LIBUSB_TRANSFER_COMPLETED) {
+ boost::this_thread::sleep(boost::posix_time::milliseconds(10));
+ }
}
+ //shutdown the threads
+ _threads_running = false;
+ _thread_group.interrupt_all();
+ _thread_group.join_all();
}
managed_recv_buffer::sptr get_recv_buff(double timeout){