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();
|
auto f = task->get_future();
|
||||||
_io_queue.push(task);
|
_io_queue.push(task);
|
||||||
|
interruptRead(false); // Alert listener to prioritise
|
||||||
cv.wait(lock, [&top_of_queue]{ return top_of_queue; });
|
cv.wait(lock, [&top_of_queue]{ return top_of_queue; });
|
||||||
auto status = f.wait_for(global_config->ioTimeout());
|
auto status = f.wait_for(global_config->ioTimeout());
|
||||||
if(status == std::future_status::timeout) {
|
if(status == std::future_status::timeout) {
|
||||||
|
@ -399,7 +400,7 @@ int RawDevice::_readReport(std::vector<uint8_t> &report,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawDevice::interruptRead()
|
void RawDevice::interruptRead(bool wait_for_halt)
|
||||||
{
|
{
|
||||||
char c = 0;
|
char c = 0;
|
||||||
if(-1 == write(_pipe[1], &c, sizeof(char)))
|
if(-1 == write(_pipe[1], &c, sizeof(char)))
|
||||||
|
@ -407,7 +408,8 @@ void RawDevice::interruptRead()
|
||||||
"interruptRead write pipe failed");
|
"interruptRead write pipe failed");
|
||||||
|
|
||||||
// Ensure I/O has halted
|
// Ensure I/O has halted
|
||||||
std::lock_guard<std::mutex> lock(_dev_io);
|
if(wait_for_halt)
|
||||||
|
std::lock_guard<std::mutex> lock(_dev_io);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawDevice::listen()
|
void RawDevice::listen()
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace raw
|
||||||
|
|
||||||
std::vector<uint8_t> sendReport(const std::vector<uint8_t>& report);
|
std::vector<uint8_t> sendReport(const std::vector<uint8_t>& report);
|
||||||
void sendReportNoResponse(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 listen();
|
||||||
void listenAsync();
|
void listenAsync();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user