Fix issue where I/O would hang
RawDevice will now interruptRead() on pushing an event to the I/O queue. This will prevent the listener from waiting for an event to be received before handling an I/O request.
This commit is contained in:
parent
cfcdca00a0
commit
9607c32520
|
@ -187,6 +187,7 @@ std::vector<uint8_t> RawDevice::sendReport(const std::vector<uint8_t>& report)
|
|||
});
|
||||
auto f = task->get_future();
|
||||
_io_queue.push(task);
|
||||
interruptRead(false); // Alert listener to prioritise
|
||||
cv.wait(lock, [&top_of_queue]{ return top_of_queue; });
|
||||
auto status = f.wait_for(global_config->ioTimeout());
|
||||
if(status == std::future_status::timeout) {
|
||||
|
@ -399,7 +400,7 @@ int RawDevice::_readReport(std::vector<uint8_t> &report,
|
|||
return ret;
|
||||
}
|
||||
|
||||
void RawDevice::interruptRead()
|
||||
void RawDevice::interruptRead(bool wait_for_halt)
|
||||
{
|
||||
char c = 0;
|
||||
if(-1 == write(_pipe[1], &c, sizeof(char)))
|
||||
|
@ -407,6 +408,7 @@ void RawDevice::interruptRead()
|
|||
"interruptRead write pipe failed");
|
||||
|
||||
// Ensure I/O has halted
|
||||
if(wait_for_halt)
|
||||
std::lock_guard<std::mutex> lock(_dev_io);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace raw
|
|||
|
||||
std::vector<uint8_t> sendReport(const std::vector<uint8_t>& report);
|
||||
void sendReportNoResponse(const std::vector<uint8_t>& report);
|
||||
void interruptRead();
|
||||
void interruptRead(bool wait_for_halt=true);
|
||||
|
||||
void listen();
|
||||
void listenAsync();
|
||||
|
|
Loading…
Reference in New Issue
Block a user