Skip to content

Commit

Permalink
Support ESP-IDF without flags
Browse files Browse the repository at this point in the history
Updates #1703
  • Loading branch information
Thomasdezeeuw committed May 25, 2024
1 parent 309daae commit 56809e1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/poll.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(all(
unix,
not(mio_unsupported_force_poll_poll),
not(any(target_os = "solaris", target_os = "vita"))
not(any(target_os = "espidf", 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 +430,7 @@ 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 = "solaris", target_os = "vita")),
))]
impl AsRawFd for Poll {
fn as_raw_fd(&self) -> RawFd {
Expand Down Expand Up @@ -721,7 +721,7 @@ 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 = "solaris", target_os = "vita")),
))]
impl AsRawFd for Registry {
fn as_raw_fd(&self) -> RawFd {
Expand All @@ -733,7 +733,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 = "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
26 changes: 16 additions & 10 deletions src/sys/unix/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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 +63,17 @@ 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 +123,7 @@ 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,9 +150,12 @@ 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(
target_os = "android",
target_os = "espidf",
target_os = "linux",
)
))]
pub(crate) use self::eventfd::WakerInternal;

Expand Down Expand Up @@ -269,8 +272,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 +320,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 +352,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;

0 comments on commit 56809e1

Please sign in to comment.