diff options
author | François Laignel <francois@centricular.com> | 2023-10-02 12:06:47 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2023-10-04 19:09:43 +0300 |
commit | 206c3964c83d81d79beedba170ee4bbf0b70a119 (patch) | |
tree | c48a89d5aece09ca732d4c8cfe358e157c67def9 /generic/threadshare/src | |
parent | 2ea53dd3a4942149aa0936a9fff12dfa3271c68a (diff) |
generic: threadshare: macOS fixes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1350>
Diffstat (limited to 'generic/threadshare/src')
5 files changed, 21 insertions, 63 deletions
diff --git a/generic/threadshare/src/runtime/executor/async_wrapper.rs b/generic/threadshare/src/runtime/executor/async_wrapper.rs index 0e23691ac..472050288 100644 --- a/generic/threadshare/src/runtime/executor/async_wrapper.rs +++ b/generic/threadshare/src/runtime/executor/async_wrapper.rs @@ -94,10 +94,10 @@ pub struct Async<T: Send + 'static> { pub(super) source: Arc<Source>, /// The inner I/O handle. - io: Option<T>, + pub(super) io: Option<T>, // The [`Handle`] on the [`Scheduler`] on which this Async wrapper is registered. - sched: scheduler::HandleWeak, + pub(super) sched: scheduler::HandleWeak, } impl<T: Send + 'static> Unpin for Async<T> {} diff --git a/generic/threadshare/src/runtime/executor/reactor.rs b/generic/threadshare/src/runtime/executor/reactor.rs index 4e297385f..e1f2221cd 100644 --- a/generic/threadshare/src/runtime/executor/reactor.rs +++ b/generic/threadshare/src/runtime/executor/reactor.rs @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 // This is based on https://github.com/smol-rs/async-io // with adaptations by: // diff --git a/generic/threadshare/src/runtime/executor/reactor/kqueue.rs b/generic/threadshare/src/runtime/executor/reactor/kqueue.rs index 9f31af98b..2ca28bccf 100644 --- a/generic/threadshare/src/runtime/executor/reactor/kqueue.rs +++ b/generic/threadshare/src/runtime/executor/reactor/kqueue.rs @@ -1,20 +1,15 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 +// This is based on https://github.com/smol-rs/async-io -use crate::os::kqueue::Signal; - -use polling::os::kqueue::{PollerKqueueExt, Process, ProcessOps, Signal as PollSignal}; -use polling::{Event, PollMode, Poller}; +use polling::{Event, Poller}; use std::fmt; use std::io::Result; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; -use std::process::Child; /// The raw registration into the reactor. -/// -/// This needs to be public, since it is technically exposed through the `QueueableSealed` trait. #[doc(hidden)] -pub enum Registration { +pub struct Registration { /// Raw file descriptor for readability/writability. /// /// @@ -22,22 +17,12 @@ pub enum Registration { /// /// This describes a valid file descriptor that has not been `close`d. It will not be /// closed while this object is alive. - Fd(RawFd), - - /// Raw signal number for signal delivery. - Signal(Signal), - - /// Process for process termination. - Process(Child), + raw: RawFd, } impl fmt::Debug for Registration { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Fd(raw) => fmt::Debug::fmt(raw, f), - Self::Signal(signal) => fmt::Debug::fmt(signal, f), - Self::Process(process) => fmt::Debug::fmt(process, f), - } + fmt::Debug::fmt(&self.raw, f) } } @@ -48,61 +33,31 @@ impl Registration { /// /// The provided file descriptor must be valid and not be closed while this object is alive. pub(crate) unsafe fn new(f: impl AsFd) -> Self { - Self::Fd(f.as_fd().as_raw_fd()) + Self { + raw: f.as_fd().as_raw_fd(), + } } /// Registers the object into the reactor. #[inline] pub(crate) fn add(&self, poller: &Poller, token: usize) -> Result<()> { - match self { - Self::Fd(raw) => { - // SAFETY: This object's existence validates the invariants of Poller::add - unsafe { poller.add(*raw, Event::none(token)) } - } - Self::Signal(signal) => { - poller.add_filter(PollSignal(signal.0), token, PollMode::Oneshot) - } - Self::Process(process) => poller.add_filter( - unsafe { Process::new(process, ProcessOps::Exit) }, - token, - PollMode::Oneshot, - ), - } + // SAFETY: This object's existence validates the invariants of Poller::add + unsafe { poller.add(self.raw, Event::none(token)) } } /// Re-registers the object into the reactor. #[inline] pub(crate) fn modify(&self, poller: &Poller, interest: Event) -> Result<()> { - match self { - Self::Fd(raw) => { - // SAFETY: self.raw is a valid file descriptor - let fd = unsafe { BorrowedFd::borrow_raw(*raw) }; - poller.modify(fd, interest) - } - Self::Signal(signal) => { - poller.modify_filter(PollSignal(signal.0), interest.key, PollMode::Oneshot) - } - Self::Process(process) => poller.modify_filter( - unsafe { Process::new(process, ProcessOps::Exit) }, - interest.key, - PollMode::Oneshot, - ), - } + // SAFETY: self.raw is a valid file descriptor + let fd = unsafe { BorrowedFd::borrow_raw(self.raw) }; + poller.modify(fd, interest) } /// Deregisters the object from the reactor. #[inline] pub(crate) fn delete(&self, poller: &Poller) -> Result<()> { - match self { - Self::Fd(raw) => { - // SAFETY: self.raw is a valid file descriptor - let fd = unsafe { BorrowedFd::borrow_raw(*raw) }; - poller.delete(fd) - } - Self::Signal(signal) => poller.delete_filter(PollSignal(signal.0)), - Self::Process(process) => { - poller.delete_filter(unsafe { Process::new(process, ProcessOps::Exit) }) - } - } + // SAFETY: self.raw is a valid file descriptor + let fd = unsafe { BorrowedFd::borrow_raw(self.raw) }; + poller.delete(fd) } } diff --git a/generic/threadshare/src/runtime/executor/reactor/unix.rs b/generic/threadshare/src/runtime/executor/reactor/unix.rs index b2f9b1b20..75ac60ac7 100644 --- a/generic/threadshare/src/runtime/executor/reactor/unix.rs +++ b/generic/threadshare/src/runtime/executor/reactor/unix.rs @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 +// This is based on https://github.com/smol-rs/async-io use polling::{Event, Poller}; diff --git a/generic/threadshare/src/runtime/executor/reactor/windows.rs b/generic/threadshare/src/runtime/executor/reactor/windows.rs index 1c92f00a6..e29056044 100644 --- a/generic/threadshare/src/runtime/executor/reactor/windows.rs +++ b/generic/threadshare/src/runtime/executor/reactor/windows.rs @@ -1,4 +1,5 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 +// This is based on https://github.com/smol-rs/async-io use polling::{Event, Poller}; use std::fmt; |