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

Fallback to poll(2) implementation without rust flags #1789

Merged
merged 3 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 19 additions & 4 deletions src/poll.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
use std::os::unix::io::{AsRawFd, RawFd};
#[cfg(all(debug_assertions, not(target_os = "wasi")))]
Expand Down Expand Up @@ -430,7 +435,12 @@ impl Poll {
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
impl AsRawFd for Poll {
fn as_raw_fd(&self) -> RawFd {
Expand Down Expand Up @@ -721,7 +731,12 @@ impl fmt::Debug for Registry {
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
impl AsRawFd for Registry {
fn as_raw_fd(&self) -> RawFd {
Expand All @@ -733,7 +748,7 @@ cfg_os_poll! {
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita")),
not(any(target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita")),
))]
#[test]
pub fn as_raw_fd() {
Expand Down
6 changes: 3 additions & 3 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ cfg_os_poll! {

cfg_io_source! {
// Both `kqueue` and `epoll` don't need to hold any user space state.
#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris", target_os = "vita")))]
#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita")))]
mod stateless_io_source {
use std::io;
#[cfg(target_os = "hermit")]
Expand Down Expand Up @@ -93,10 +93,10 @@ cfg_os_poll! {
}
}

#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris",target_os = "vita")))]
#[cfg(not(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita")))]
pub(crate) use self::stateless_io_source::IoSourceState;

#[cfg(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris", target_os = "vita"))]
#[cfg(any(mio_unsupported_force_poll_poll, target_os = "espidf", target_os = "hermit", target_os = "solaris", target_os = "vita"))]
pub(crate) use self::selector::IoSourceState;
}

Expand Down
14 changes: 11 additions & 3 deletions src/sys/unix/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,30 @@ pub(crate) use self::epoll::{event, Event, Events, Selector};

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
mod poll;

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
pub(crate) use self::poll::{event, Event, Events, Selector};

cfg_io_source! {
#[cfg(any(mio_unsupported_force_poll_poll, target_os = "hermit", target_os = "solaris", target_os = "vita"))]
#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
))]
pub(crate) use self::poll::IoSourceState;
}

Expand Down
11 changes: 6 additions & 5 deletions src/sys/unix/selector/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
// Permission to use this code has been granted by original author:
// https://github.com/tokio-rs/mio/pull/1602#issuecomment-1218441031

use crate::sys::unix::selector::LOWEST_FD;
use crate::sys::unix::waker::WakerInternal;
use crate::{Interest, Token};
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
#[cfg(target_os = "hermit")]
use std::os::hermit::io::{AsRawFd, RawFd};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd};
use std::sync::atomic::AtomicBool;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::{Arc, Condvar, Mutex};
use std::time::Duration;
use std::{cmp, fmt, io};

use crate::sys::unix::selector::LOWEST_FD;
use crate::sys::unix::waker::WakerInternal;
use crate::{Interest, Token};

/// Unique id for use as `SelectorId`.
#[cfg(debug_assertions)]
static NEXT_ID: AtomicUsize = AtomicUsize::new(1);
Expand Down Expand Up @@ -74,6 +74,7 @@ impl Selector {
pub fn wake(&self, token: Token) -> io::Result<()> {
self.state.wake(token)
}

cfg_io_source! {
#[cfg(debug_assertions)]
pub fn id(&self) -> usize {
Expand Down
43 changes: 30 additions & 13 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
target_os = "watchos",
)
)),
not(any(target_os = "solaris", target_os = "vita", target_os = "hermit")),
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
mod fdbased {
#[cfg(all(
Expand Down Expand Up @@ -63,17 +68,22 @@ mod fdbased {
target_os = "watchos",
)
)),
not(any(target_os = "solaris", target_os = "vita", target_os = "hermit")),
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita"
)),
))]
pub use self::fdbased::Waker;

#[cfg(all(
not(mio_unsupported_force_waker_pipe),
any(
target_os = "linux",
target_os = "android",
target_os = "espidf",
target_os = "hermit"
target_os = "hermit",
target_os = "linux",
)
))]
mod eventfd {
Expand Down Expand Up @@ -123,7 +133,11 @@ mod eventfd {
}
}

#[cfg(any(mio_unsupported_force_poll_poll, target_os = "hermit"))]
#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit"
))]
pub fn ack_and_reset(&self) {
let _ = self.reset();
}
Expand All @@ -150,15 +164,15 @@ mod eventfd {
}

#[cfg(all(
mio_unsupported_force_poll_poll,
not(mio_unsupported_force_waker_pipe),
any(target_os = "linux", target_os = "android", target_os = "espidf")
any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
)
))]
pub(crate) use self::eventfd::WakerInternal;

#[cfg(target_os = "hermit")]
pub(crate) use self::eventfd::WakerInternal;

#[cfg(all(
not(mio_unsupported_force_waker_pipe),
any(
Expand Down Expand Up @@ -269,8 +283,9 @@ mod pipe {

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "solaris",
target_os = "vita"
target_os = "vita",
))]
pub fn ack_and_reset(&self) {
self.empty();
Expand Down Expand Up @@ -316,9 +331,10 @@ pub(crate) use self::pipe::WakerInternal;

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
mod poll {
use crate::sys::Selector;
Expand Down Expand Up @@ -347,8 +363,9 @@ mod poll {

#[cfg(any(
mio_unsupported_force_poll_poll,
target_os = "espidf",
target_os = "hermit",
target_os = "solaris",
target_os = "vita",
target_os = "hermit"
))]
pub use self::poll::Waker;