From 9607c325201ac665643b01b7a47e5f709dc15a84 Mon Sep 17 00:00:00 2001 From: pixl Date: Sat, 18 Jul 2020 22:57:51 -0400 Subject: [PATCH] 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. --- src/logid/backend/raw/RawDevice.cpp | 6 ++++-- src/logid/backend/raw/RawDevice.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/logid/backend/raw/RawDevice.cpp b/src/logid/backend/raw/RawDevice.cpp index e7f561f..0493862 100644 --- a/src/logid/backend/raw/RawDevice.cpp +++ b/src/logid/backend/raw/RawDevice.cpp @@ -187,6 +187,7 @@ std::vector RawDevice::sendReport(const std::vector& 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 &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,7 +408,8 @@ void RawDevice::interruptRead() "interruptRead write pipe failed"); // Ensure I/O has halted - std::lock_guard lock(_dev_io); + if(wait_for_halt) + std::lock_guard lock(_dev_io); } void RawDevice::listen() diff --git a/src/logid/backend/raw/RawDevice.h b/src/logid/backend/raw/RawDevice.h index e625944..9ec935a 100644 --- a/src/logid/backend/raw/RawDevice.h +++ b/src/logid/backend/raw/RawDevice.h @@ -53,7 +53,7 @@ namespace raw std::vector sendReport(const std::vector& report); void sendReportNoResponse(const std::vector& report); - void interruptRead(); + void interruptRead(bool wait_for_halt=true); void listen(); void listenAsync();