From ed4aefbb9595c54dfe54074755c985f28385a0cf Mon Sep 17 00:00:00 2001 From: pip Date: Sun, 27 Feb 2011 21:15:32 +0000 Subject: [PATCH] Removed unneeded mutex in the enumeration thread. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2911 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../src/plugins/rawhid/pjrc_rawhid_unix.cpp | 5 ++--- .../src/plugins/rawhid/pjrc_rawhid_win.cpp | 12 ++++------- .../src/plugins/rawhid/rawhidplugin.cpp | 20 +++++++------------ .../src/plugins/rawhid/rawhidplugin.h | 4 ---- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_unix.cpp b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_unix.cpp index 8a687263b..f4ddeba7e 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_unix.cpp +++ b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_unix.cpp @@ -275,9 +275,7 @@ QString pjrc_rawhid::getserial(int num) { // void pjrc_rawhid::close(int num) { - hid_t *hid = get_hid(num); - if (hid && !hid->open) - hid_close(hid); + hid_close(get_hid(num)); } // Chuck Robey wrote a real HID report parser @@ -358,6 +356,7 @@ void pjrc_rawhid::free_all_hid(void) void pjrc_rawhid::hid_close(hid_t *hid) { if (!hid) return; + if (!hid->handle || !hid->open) return; usb_release_interface(hid->usb, hid->iface); diff --git a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp index 5c0bfd3b9..3562bd501 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp +++ b/ground/openpilotgcs/src/plugins/rawhid/pjrc_rawhid_win.cpp @@ -341,9 +341,7 @@ QString pjrc_rawhid::getserial(int num) // void pjrc_rawhid::close(int num) { - hid_t *hid = get_hid(num); - if (hid && hid->open) - hid_close(hid); + hid_close(get_hid(num)); } void pjrc_rawhid::add_hid(hid_t *h) @@ -388,12 +386,10 @@ void pjrc_rawhid::free_all_hid(void) void pjrc_rawhid::hid_close(hid_t *hid) { if (!hid) return; + if (!hid->handle || !hid->open) return; - if (hid->handle) - { - CloseHandle(hid->handle); - hid->handle = NULL; - } + CloseHandle(hid->handle); + hid->handle = NULL; } void pjrc_rawhid::print_win32_err(void) diff --git a/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp b/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp index ecdcc98db..5273d59fd 100644 --- a/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp +++ b/ground/openpilotgcs/src/plugins/rawhid/rawhidplugin.cpp @@ -49,9 +49,7 @@ RawHIDEnumerationThread::RawHIDEnumerationThread(RawHIDConnection *rawhid) : RawHIDEnumerationThread::~RawHIDEnumerationThread() { - mutex.lock(); - m_rawhid = NULL; // safe guard - mutex.unlock(); + m_rawhid = NULL; // safe guard m_running = false; @@ -62,8 +60,6 @@ RawHIDEnumerationThread::~RawHIDEnumerationThread() void RawHIDEnumerationThread::onRawHidConnectionDestroyed(QObject *obj) // Pip { - QMutexLocker locker(&mutex); - if (!m_rawhid || m_rawhid != obj) return; @@ -78,8 +74,6 @@ void RawHIDEnumerationThread::run() while (m_running) { - mutex.lock(); // Pip - // update available devices every second (doesn't need more) if (m_rawhid) { @@ -103,8 +97,6 @@ void RawHIDEnumerationThread::run() else counter = 0; - mutex.unlock(); // Pip - msleep(10); } } @@ -153,13 +145,15 @@ QStringList RawHIDConnection::availableDevices() QStringList devices; - if (enablePolling) { + if (enablePolling) + { pjrc_rawhid dev; - //open all device we can + + // open all device we can int opened = dev.open(USB_MAX_DEVICES, USB_VID, USB_PID, USB_USAGE_PAGE, USB_USAGE); - //for each devices found, get serial number and close it back - for(int i=0; i