From 7571be1f54294e3dc59cf0a87a1a2c3124742309 Mon Sep 17 00:00:00 2001 From: pixl Date: Thu, 18 Jun 2020 02:28:43 -0400 Subject: [PATCH] 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. --- src/logid/backend/raw/RawDevice.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/logid/backend/raw/RawDevice.cpp b/src/logid/backend/raw/RawDevice.cpp index 0def59c..eeabeb5 100644 --- a/src/logid/backend/raw/RawDevice.cpp +++ b/src/logid/backend/raw/RawDevice.cpp @@ -91,7 +91,7 @@ std::vector RawDevice::sendReport(const std::vector& report) { 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. */ if(continue_listen) { @@ -118,9 +118,8 @@ std::vector RawDevice::_respondToReport // All reports have the device index at byte 2 if(response[1] != request[1]) { - std::thread([this](std::vector report) { - this->handleEvent(report); - }, request).detach(); + if(continue_listen) + this->handleEvent(response); continue; } @@ -130,9 +129,8 @@ std::vector RawDevice::_respondToReport if(hidpp::ReportType::Short != response[0] && hidpp::ReportType::Long != response[0]) { - std::thread([this](std::vector report) { - this->handleEvent(report); - }, request).detach(); + if(continue_listen) + this->handleEvent(response); continue; } @@ -160,9 +158,8 @@ std::vector RawDevice::_respondToReport return response; } - std::thread([this](std::vector report) { - this->handleEvent(report); - }, request).detach(); + if(continue_listen) + this->handleEvent(response); } } @@ -246,9 +243,8 @@ void RawDevice::listen() } std::vector report; _readReport(report, MAX_DATA_LENGTH); - std::thread([this](std::vector report) { - this->handleEvent(report); - }, report).detach(); + + this->handleEvent(report); } continue_listen = false;