From d1490e549bbf6fefd57e98dda701556f67e00db6 Mon Sep 17 00:00:00 2001 From: Nikolay Arhipov Date: Fri, 19 Apr 2024 09:44:43 +0300 Subject: [PATCH] Added CI check and inlined hack into pop_notification --- .github/workflows/ci.yml | 3 +++ src/poll.rs | 41 ++++++++++++++++++---------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef7d339..e27998b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -126,6 +126,9 @@ jobs: - name: Check haiku if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' run: cargo check -Z build-std --target x86_64-unknown-haiku + - name: Check vita + if: startsWith(matrix.rust, 'nightly') && matrix.os == 'ubuntu-latest' + run: cargo check -Z build-std --target armv7-sony-vita-newlibeabihf wine: runs-on: ubuntu-22.04 diff --git a/src/poll.rs b/src/poll.rs index 8183188..cba72fa 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -222,28 +222,7 @@ impl Poller { if self.notified.swap(false, Ordering::SeqCst) { // `notify` will have sent a notification in case we were polling. We weren't, // so remove it. - - // Pipes on Vita do not guarantee that after `write` call succeeds, the - // data becomes immediately available for reading on the other side of the pipe. - // To ensure that the notification is not lost, the read side of the pipe is temporarily - // switched to blocking for a single `read` call. - #[cfg(target_os = "vita")] - rustix::fs::fcntl_setfl( - &self.notify.read_pipe, - rustix::fs::fcntl_getfl(&self.notify.read_pipe)? - & !rustix::fs::OFlags::NONBLOCK, - )?; - - let notification = self.notify.pop_notification(); - - #[cfg(target_os = "vita")] - rustix::fs::fcntl_setfl( - &self.notify.read_pipe, - rustix::fs::fcntl_getfl(&self.notify.read_pipe)? - | rustix::fs::OFlags::NONBLOCK, - )?; - - return notification; + return self.notify.pop_notification(); } else if self.waiting_operations.load(Ordering::SeqCst) == 0 { break; } @@ -667,7 +646,7 @@ mod notify { pub(super) struct Notify { /// The file descriptor of the read half of the notify pipe. This is also stored as the first /// file descriptor in `fds.poll_fds`. - pub(super) read_pipe: OwnedFd, + read_pipe: OwnedFd, /// The file descriptor of the write half of the notify pipe. /// /// Data is written to this to wake up the current instance of `Poller::wait`, which can occur when the @@ -720,8 +699,24 @@ mod notify { /// Pops a notification (if any) from the pipe. pub(super) fn pop_notification(&self) -> Result<(), io::Error> { + // Pipes on Vita do not guarantee that after `write` call succeeds, the + // data becomes immediately available for reading on the other side of the pipe. + // To ensure that the notification is not lost, the read side of the pipe is temporarily + // switched to blocking for a single `read` call. + #[cfg(target_os = "vita")] + rustix::fs::fcntl_setfl( + &self.read_pipe, + rustix::fs::fcntl_getfl(&self.read_pipe)? & !rustix::fs::OFlags::NONBLOCK, + )?; + read(&self.read_pipe, &mut [0; 1])?; + #[cfg(target_os = "vita")] + rustix::fs::fcntl_setfl( + &self.read_pipe, + rustix::fs::fcntl_getfl(&self.read_pipe)? | rustix::fs::OFlags::NONBLOCK, + )?; + Ok(()) }