File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,12 @@ void AsyncUsbTransceiverBase::TransferCompleteInternal(
6262 m_device_disconnected = true ;
6363
6464 TransferComplete (transfer);
65+
66+ {
67+ ola::thread::MutexLocker locker (&m_mutex);
68+ if (m_inflight.empty ())
69+ m_cond.Signal ();
70+ }
6571}
6672
6773AsyncUsbTransceiverBase::AsyncUsbTransceiverBase (LibUsbAdaptor *adaptor,
@@ -83,6 +89,14 @@ AsyncUsbTransceiverBase::~AsyncUsbTransceiverBase() {
8389
8490 CancelTransfer ();
8591
92+ while (!m_inflight.empty ()) {
93+ /* Wait for cancelled transfers to complete, freeing the transfers
94+ * below before the callbacks happen is undefined behaviour according
95+ * to libusb docs. Here's to hoping this destructor runs in a different
96+ * thread than the one processing libusb callbacks. */
97+ m_cond.Wait (&m_mutex);
98+ }
99+
86100 m_adaptor->UnrefDevice (m_usb_device);
87101
88102 while (!m_idle.empty ()) {
Original file line number Diff line number Diff line change @@ -134,6 +134,7 @@ class AsyncUsbTransceiverBase {
134134 std::queue<struct libusb_transfer *> m_idle; // GUARDED_BY(m_mutex);
135135
136136 ola::thread::Mutex m_mutex;
137+ ola::thread::ConditionVariable m_cond;
137138
138139 private:
139140 /* *
You can’t perform that action at this time.
0 commit comments