Don't create a new thread for each raw event
Threads should be created as necessary, there is no reason to launch a simple event handler in a new thread.
This commit is contained in:
parent
cc025d3b96
commit
7571be1f54
|
@ -91,7 +91,7 @@ std::vector<uint8_t> RawDevice::sendReport(const std::vector<uint8_t>& report)
|
||||||
{
|
{
|
||||||
assert(supportedReportID(report[0]));
|
assert(supportedReportID(report[0]));
|
||||||
|
|
||||||
/* If the listener will stop, handle I/O manually.
|
/* If the listener will stop, handle I/O manually.
|
||||||
* Otherwise, push to queue and wait for result. */
|
* Otherwise, push to queue and wait for result. */
|
||||||
if(continue_listen)
|
if(continue_listen)
|
||||||
{
|
{
|
||||||
|
@ -118,9 +118,8 @@ std::vector<uint8_t> RawDevice::_respondToReport
|
||||||
// All reports have the device index at byte 2
|
// All reports have the device index at byte 2
|
||||||
if(response[1] != request[1])
|
if(response[1] != request[1])
|
||||||
{
|
{
|
||||||
std::thread([this](std::vector<uint8_t> report) {
|
if(continue_listen)
|
||||||
this->handleEvent(report);
|
this->handleEvent(response);
|
||||||
}, request).detach();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,9 +129,8 @@ std::vector<uint8_t> RawDevice::_respondToReport
|
||||||
if(hidpp::ReportType::Short != response[0] &&
|
if(hidpp::ReportType::Short != response[0] &&
|
||||||
hidpp::ReportType::Long != response[0])
|
hidpp::ReportType::Long != response[0])
|
||||||
{
|
{
|
||||||
std::thread([this](std::vector<uint8_t> report) {
|
if(continue_listen)
|
||||||
this->handleEvent(report);
|
this->handleEvent(response);
|
||||||
}, request).detach();
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +158,8 @@ std::vector<uint8_t> RawDevice::_respondToReport
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::thread([this](std::vector<uint8_t> report) {
|
if(continue_listen)
|
||||||
this->handleEvent(report);
|
this->handleEvent(response);
|
||||||
}, request).detach();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,9 +243,8 @@ void RawDevice::listen()
|
||||||
}
|
}
|
||||||
std::vector<uint8_t> report;
|
std::vector<uint8_t> report;
|
||||||
_readReport(report, MAX_DATA_LENGTH);
|
_readReport(report, MAX_DATA_LENGTH);
|
||||||
std::thread([this](std::vector<uint8_t> report) {
|
|
||||||
this->handleEvent(report);
|
this->handleEvent(report);
|
||||||
}, report).detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue_listen = false;
|
continue_listen = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user