Skip to content

Commit

Permalink
Added CI check and inlined hack into pop_notification
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarh committed Apr 19, 2024
1 parent ac07039 commit d1490e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 18 additions & 23 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit d1490e5

Please sign in to comment.