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:
		@@ -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;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user