From 6163589ac7f9809903c9d52a3b0591de77e722c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Laignel?= Date: Tue, 14 Dec 2021 19:40:27 +0100 Subject: ts/executor: replace tokio with smol-like implementation The threadshare executor was based on a modified version of tokio which implemented the throttling strategy in the BasicScheduler. Upstream tokio codebase has significantly diverged from what it was when the throttling strategy was implemented making it hard to follow. This means that we can hardly get updates from the upstream project and when we cherry pick fixes, we can't reflect the state of the project on our fork's version. As a consequence, tools such as cargo-deny can't check for RUSTSEC fixes in our fork. The smol ecosystem makes it quite easy to implement and maintain a custom async executor. This MR imports the smol parts that need modifications to comply with the threadshare model and implements a throttling executor in place of the tokio fork. Networking tokio specific types are replaced with Async wrappers in the spirit of [smol-rs/async-io]. Note however that the Async wrappers needed modifications in order to use the per thread Reactor model. This means that higher level upstream networking crates such as [async-net] can not be used with our Async implementation. Based on the example benchmark with ts-udpsrc, performances seem on par with what we achieved using the tokio fork. Fixes https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/118 Related to https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/604 --- generic/threadshare/src/socket.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'generic/threadshare/src/socket.rs') diff --git a/generic/threadshare/src/socket.rs b/generic/threadshare/src/socket.rs index 420e0f345..0e544c3e4 100644 --- a/generic/threadshare/src/socket.rs +++ b/generic/threadshare/src/socket.rs @@ -24,12 +24,14 @@ use gst::{gst_debug, gst_error, gst_log}; use once_cell::sync::Lazy; -use std::io; - use gio::prelude::*; use std::error; use std::fmt; +use std::io; +use std::net::UdpSocket; + +use crate::runtime::Async; #[cfg(unix)] use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; @@ -302,7 +304,7 @@ unsafe fn dup_socket(socket: usize) -> usize { socket } -pub fn wrap_socket(socket: &tokio::net::UdpSocket) -> Result { +pub fn wrap_socket(socket: &Async) -> Result { #[cfg(unix)] unsafe { let fd = libc::dup(socket.as_raw_fd()); @@ -328,9 +330,7 @@ pub fn wrap_socket(socket: &tokio::net::UdpSocket) -> Result