mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-28 22:41:02 +00:00
generic: threadshare: macOS fixes
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1344>
This commit is contained in:
parent
450ffbe452
commit
a1ad3379ca
6 changed files with 23 additions and 65 deletions
|
@ -94,10 +94,10 @@ pub struct Async<T: Send + 'static> {
|
||||||
pub(super) source: Arc<Source>,
|
pub(super) source: Arc<Source>,
|
||||||
|
|
||||||
/// The inner I/O handle.
|
/// 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.
|
// 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> {}
|
impl<T: Send + 'static> Unpin for Async<T> {}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
// This is based on https://github.com/smol-rs/async-io
|
// This is based on https://github.com/smol-rs/async-io
|
||||||
// with adaptations by:
|
// with adaptations by:
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// 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::{Event, Poller};
|
||||||
|
|
||||||
use polling::os::kqueue::{PollerKqueueExt, Process, ProcessOps, Signal as PollSignal};
|
|
||||||
use polling::{Event, PollMode, Poller};
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Result;
|
use std::io::Result;
|
||||||
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
|
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
|
||||||
use std::process::Child;
|
|
||||||
|
|
||||||
/// The raw registration into the reactor.
|
/// The raw registration into the reactor.
|
||||||
///
|
|
||||||
/// This needs to be public, since it is technically exposed through the `QueueableSealed` trait.
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub enum Registration {
|
pub struct Registration {
|
||||||
/// Raw file descriptor for readability/writability.
|
/// 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
|
/// This describes a valid file descriptor that has not been `close`d. It will not be
|
||||||
/// closed while this object is alive.
|
/// closed while this object is alive.
|
||||||
Fd(RawFd),
|
raw: RawFd,
|
||||||
|
|
||||||
/// Raw signal number for signal delivery.
|
|
||||||
Signal(Signal),
|
|
||||||
|
|
||||||
/// Process for process termination.
|
|
||||||
Process(Child),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Registration {
|
impl fmt::Debug for Registration {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
fmt::Debug::fmt(&self.raw, f)
|
||||||
Self::Fd(raw) => fmt::Debug::fmt(raw, f),
|
|
||||||
Self::Signal(signal) => fmt::Debug::fmt(signal, f),
|
|
||||||
Self::Process(process) => fmt::Debug::fmt(process, f),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,61 +33,31 @@ impl Registration {
|
||||||
///
|
///
|
||||||
/// The provided file descriptor must be valid and not be closed while this object is alive.
|
/// 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 {
|
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.
|
/// Registers the object into the reactor.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn add(&self, poller: &Poller, token: usize) -> Result<()> {
|
pub(crate) fn add(&self, poller: &Poller, token: usize) -> Result<()> {
|
||||||
match self {
|
// SAFETY: This object's existence validates the invariants of Poller::add
|
||||||
Self::Fd(raw) => {
|
unsafe { poller.add(self.raw, Event::none(token)) }
|
||||||
// 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,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Re-registers the object into the reactor.
|
/// Re-registers the object into the reactor.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn modify(&self, poller: &Poller, interest: Event) -> Result<()> {
|
pub(crate) fn modify(&self, poller: &Poller, interest: Event) -> Result<()> {
|
||||||
match self {
|
// SAFETY: self.raw is a valid file descriptor
|
||||||
Self::Fd(raw) => {
|
let fd = unsafe { BorrowedFd::borrow_raw(self.raw) };
|
||||||
// SAFETY: self.raw is a valid file descriptor
|
poller.modify(fd, interest)
|
||||||
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,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deregisters the object from the reactor.
|
/// Deregisters the object from the reactor.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn delete(&self, poller: &Poller) -> Result<()> {
|
pub(crate) fn delete(&self, poller: &Poller) -> Result<()> {
|
||||||
match self {
|
// SAFETY: self.raw is a valid file descriptor
|
||||||
Self::Fd(raw) => {
|
let fd = unsafe { BorrowedFd::borrow_raw(self.raw) };
|
||||||
// SAFETY: self.raw is a valid file descriptor
|
poller.delete(fd)
|
||||||
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) })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
// This is based on https://github.com/smol-rs/async-io
|
||||||
|
|
||||||
use polling::{Event, Poller};
|
use polling::{Event, Poller};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
// This is based on https://github.com/smol-rs/async-io
|
||||||
|
|
||||||
use polling::{Event, Poller};
|
use polling::{Event, Poller};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
|
@ -43,7 +43,7 @@ fn test_push() {
|
||||||
let handler = thread::spawn(move || {
|
let handler = thread::spawn(move || {
|
||||||
use std::net;
|
use std::net;
|
||||||
|
|
||||||
let listener = net::TcpListener::bind("0.0.0.0:5000").unwrap();
|
let listener = net::TcpListener::bind("0.0.0.0:5010").unwrap();
|
||||||
listening_tx.send(()).unwrap();
|
listening_tx.send(()).unwrap();
|
||||||
let stream = listener.incoming().next().unwrap();
|
let stream = listener.incoming().next().unwrap();
|
||||||
let buffer = [0; 160];
|
let buffer = [0; 160];
|
||||||
|
@ -59,7 +59,7 @@ fn test_push() {
|
||||||
let caps = gst::Caps::builder("foo/bar").build();
|
let caps = gst::Caps::builder("foo/bar").build();
|
||||||
let tcpclientsrc = gst::ElementFactory::make("ts-tcpclientsrc")
|
let tcpclientsrc = gst::ElementFactory::make("ts-tcpclientsrc")
|
||||||
.property("caps", &caps)
|
.property("caps", &caps)
|
||||||
.property("port", 5000i32)
|
.property("port", 5010i32)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let appsink = gst_app::AppSink::builder()
|
let appsink = gst_app::AppSink::builder()
|
||||||
|
|
Loading…
Reference in a new issue