gpio-presence: check event before event_read()
I observed that event_read doesn't clear EPOLLIN immediately;
it's cleared during the next epoll check.
The failure scenario is: fdio.next is triggered, but the GPIO event
queue is empty, causing event_read to block the task.
To fix this, I added event_wait to ensure the event is available before
calling event_read() and avoid blocking.
Tested on Ventura: After making the change, the issue has been fixed.
- Plug leak cable
- Unplug leak cable
Change-Id: I68f5243ca4d6feb4d99242e9b1093089a6d14926
Signed-off-by: Eldin Lee <eldin.lee@quantatw.com>
diff --git a/src/gpio-presence/gpio_presence_manager.cpp b/src/gpio-presence/gpio_presence_manager.cpp
index 856408e..a543f50 100644
--- a/src/gpio-presence/gpio_presence_manager.cpp
+++ b/src/gpio-presence/gpio_presence_manager.cpp
@@ -244,6 +244,15 @@
debug("Received gpio event for {LINENAME}", "LINENAME", gpioLine);
+ // event_read() does not clear the EPOLLIN flag immediately; it is
+ // cleared during the subsequent epoll check. Therefore, call event_wait
+ // with a zero timeout to ensure that event_read() is only invoked when
+ // an event is available, preventing it from blocking.
+ if (!gpioLines[gpioLine].event_wait(std::chrono::milliseconds(0)))
+ {
+ continue;
+ }
+
gpioLines[gpioLine].event_read();
auto lineValue = gpioLines[gpioLine].get_value();