Fix BlockUntilVSync() to actually block
In my refactoring in ag/2008740 I introduced a regression where blocking
until the next vsync would busy loop instead of actually blocking on an
event on the vsync fd. The problem was I changed the poll() call to
listen for POLLIN in addition to POLLPRI. While waiting for vsync events
we only want to listen for POLLPRI.
Bug: 36495351
Test: Confirmed with debug logs the busy loop bug and that we correctly
block with this patch applied.
Change-Id: Iec4951e014575a5d0ed3cfe3fc20ea91c67edf1b
diff --git a/libs/vr/libvrflinger/hardware_composer.cpp b/libs/vr/libvrflinger/hardware_composer.cpp
index da45859..542bbd9 100644
--- a/libs/vr/libvrflinger/hardware_composer.cpp
+++ b/libs/vr/libvrflinger/hardware_composer.cpp
@@ -518,10 +518,13 @@
post_thread_cond_var_.notify_all();
}
-int HardwareComposer::PostThreadPollInterruptible(int event_fd) {
+int HardwareComposer::PostThreadPollInterruptible(int event_fd,
+ int requested_events) {
pollfd pfd[2] = {
{
- .fd = event_fd, .events = POLLPRI | POLLIN, .revents = 0,
+ .fd = event_fd,
+ .events = static_cast<short>(requested_events),
+ .revents = 0,
},
{
.fd = post_thread_interrupt_event_fd_.Get(),
@@ -645,7 +648,9 @@
// TODO(eieio): This is pretty driver specific, this should be moved to a
// separate class eventually.
int HardwareComposer::BlockUntilVSync() {
- return PostThreadPollInterruptible(primary_display_vsync_event_fd_.Get());
+ return PostThreadPollInterruptible(primary_display_vsync_event_fd_.Get(),
+ // There will be a POLLPRI event on vsync
+ POLLPRI);
}
// Waits for the next vsync and returns the timestamp of the vsync event. If
@@ -718,7 +723,7 @@
return -error;
}
- return PostThreadPollInterruptible(timer_fd);
+ return PostThreadPollInterruptible(timer_fd, POLLIN);
}
void HardwareComposer::PostThread() {