Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ported to Vita target #197

Merged
merged 10 commits into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ socket2 = "0.5.5"

[target.'cfg(unix)'.dev-dependencies]
libc = "0.2"

[target.'cfg(all(unix, not(target_os="vita")))'.dev-dependencies]
signal-hook = "0.3.17"
25 changes: 23 additions & 2 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,28 @@ 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.
return self.notify.pop_notification();

// 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;
nikarh marked this conversation as resolved.
Show resolved Hide resolved
} else if self.waiting_operations.load(Ordering::SeqCst) == 0 {
break;
}
Expand Down Expand Up @@ -646,7 +667,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`.
read_pipe: OwnedFd,
pub(super) 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
2 changes: 1 addition & 1 deletion tests/concurrent_modification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn concurrent_modify() -> io::Result<()> {
Ok(())
}

#[cfg(unix)]
#[cfg(all(unix, not(target_os = "vita")))]
#[test]
fn concurrent_interruption() -> io::Result<()> {
struct MakeItSend<T>(T);
Expand Down
Loading