mirror of https://github.com/AxioDL/boo.git
Smarter std::thread ownership for HID clients
This commit is contained in:
parent
51a097da6b
commit
1877c546ac
|
@ -22,7 +22,7 @@ class HIDDeviceIOKit : public IHIDDevice
|
|||
const std::string& m_devPath;
|
||||
std::mutex m_initMutex;
|
||||
std::condition_variable m_initCond;
|
||||
std::thread* m_thread;
|
||||
std::thread m_thread;
|
||||
|
||||
bool _sendUSBInterruptTransfer(const uint8_t* data, size_t length)
|
||||
{
|
||||
|
@ -228,11 +228,11 @@ public:
|
|||
std::unique_lock<std::mutex> lk(m_initMutex);
|
||||
DeviceToken::DeviceType dType = token.getDeviceType();
|
||||
if (dType == DeviceToken::DeviceType::USB)
|
||||
m_thread = new std::thread(_threadProcUSBLL, this);
|
||||
m_thread = std::thread(_threadProcUSBLL, this);
|
||||
else if (dType == DeviceToken::DeviceType::Bluetooth)
|
||||
m_thread = new std::thread(_threadProcBTLL, this);
|
||||
m_thread = std::thread(_threadProcBTLL, this);
|
||||
else if (dType == DeviceToken::DeviceType::GenericHID)
|
||||
m_thread = new std::thread(_threadProcHID, this);
|
||||
m_thread = std::thread(_threadProcHID, this);
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "invalid token supplied to device constructor\n");
|
||||
|
@ -244,8 +244,8 @@ public:
|
|||
~HIDDeviceIOKit()
|
||||
{
|
||||
m_runningTransferLoop = false;
|
||||
m_thread->join();
|
||||
delete m_thread;
|
||||
if (m_thread.joinable())
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class HIDDeviceUdev final : public IHIDDevice
|
|||
const std::string& m_devPath;
|
||||
std::mutex m_initMutex;
|
||||
std::condition_variable m_initCond;
|
||||
std::thread* m_thread;
|
||||
std::thread m_thread;
|
||||
|
||||
bool _sendUSBInterruptTransfer(const uint8_t* data, size_t length)
|
||||
{
|
||||
|
@ -245,11 +245,11 @@ public:
|
|||
std::unique_lock<std::mutex> lk(m_initMutex);
|
||||
DeviceToken::DeviceType dType = token.getDeviceType();
|
||||
if (dType == DeviceToken::DeviceType::USB)
|
||||
m_thread = new std::thread(_threadProcUSBLL, this);
|
||||
m_thread = std::thread(_threadProcUSBLL, this);
|
||||
else if (dType == DeviceToken::DeviceType::Bluetooth)
|
||||
m_thread = new std::thread(_threadProcBTLL, this);
|
||||
m_thread = std::thread(_threadProcBTLL, this);
|
||||
else if (dType == DeviceToken::DeviceType::GenericHID)
|
||||
m_thread = new std::thread(_threadProcHID, this);
|
||||
m_thread = std::thread(_threadProcHID, this);
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "invalid token supplied to device constructor");
|
||||
|
@ -261,8 +261,8 @@ public:
|
|||
~HIDDeviceUdev()
|
||||
{
|
||||
m_runningTransferLoop = false;
|
||||
m_thread->join();
|
||||
delete m_thread;
|
||||
if (m_thread.joinable())
|
||||
m_thread.join();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue