summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
Diffstat (limited to 'host/lib')
-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){