feat: ported to Vita target

This commit is contained in:
Nikolay Arhipov 2024-04-17 10:13:33 +03:00
parent 1c16a1e4af
commit 3b7dfbc72f
3 changed files with 30 additions and 4 deletions

View File

@ -4,7 +4,10 @@ name = "polling"
# - Update CHANGELOG.md
# - Create "v3.x.y" git tag
version = "3.6.0"
authors = ["Stjepan Glavina <stjepang@gmail.com>", "John Nunley <dev@notgull.net>"]
authors = [
"Stjepan Glavina <stjepang@gmail.com>",
"John Nunley <dev@notgull.net>",
]
edition = "2021"
rust-version = "1.63"
description = "Portable interface to epoll, kqueue, event ports, and IOCP"
@ -55,4 +58,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"

View File

@ -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;
} else if self.waiting_operations.load(Ordering::SeqCst) == 0 {
break;
}
@ -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

View File

@ -76,7 +76,7 @@ fn concurrent_modify() -> io::Result<()> {
Ok(())
}
#[cfg(unix)]
#[cfg(unix, not(target_os = "vita"))]
#[test]
fn concurrent_interruption() -> io::Result<()> {
struct MakeItSend<T>(T);