From 52d34e42a1e8846f388399c575274aa9f604413c Mon Sep 17 00:00:00 2001 From: EliasSchriefer Date: Tue, 3 Nov 2020 17:43:50 +0100 Subject: [PATCH] Update `iface_rt` behaviour to fix tokio update --- sfsmcd/src/ifaces.rs | 2 +- sfsmcd/src/main.rs | 22 +++++----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/sfsmcd/src/ifaces.rs b/sfsmcd/src/ifaces.rs index 887f849..e8ecc37 100644 --- a/sfsmcd/src/ifaces.rs +++ b/sfsmcd/src/ifaces.rs @@ -132,7 +132,7 @@ macro_rules! handle_iface { ($m:ident, |$data:ident| $($f:tt)+) => {move |$m| tokio::task::block_in_place(move || { let $data = $m.path.get_data(); // Run a Future on the dedicated tokio runtime - iface_rt_handle().block_on(async move { + iface_rt().block_on(async move { $($f)+ }) })}; diff --git a/sfsmcd/src/main.rs b/sfsmcd/src/main.rs index 80560da..7a470ab 100644 --- a/sfsmcd/src/main.rs +++ b/sfsmcd/src/main.rs @@ -12,38 +12,26 @@ mod ifaces; const DBUS_NAME: &'static str = "org.ddnss.sfs.mc"; // Interface tokio runtime -static mut IFACE_RT: Option = None; -static mut IFACE_RT_HANDLE: Option> = None; +static mut IFACE_RT: Option> = None; static IFACE_RT_INIT: std::sync::Once = std::sync::Once::new(); fn iface_name(iface: &str) -> String { DBUS_NAME.to_owned() + "." + iface } -fn iface_rt_handle() -> Arc { +fn iface_rt() -> Arc { IFACE_RT_INIT.call_once(|| { unsafe { - IFACE_RT = Some(tokio::runtime::Builder::new() + IFACE_RT = Some(Arc::new(tokio::runtime::Builder::new_multi_thread() .thread_name("iface-runtime-worker") .build() .unwrap() - ); - - IFACE_RT_HANDLE = match &IFACE_RT { - Some(iface_rt) => Some(Arc::new(iface_rt - .handle() - .clone() - )), - _ => unreachable!() - }; + )); } }); unsafe { - match &IFACE_RT_HANDLE { - Some(iface_rt_handle) => iface_rt_handle.clone(), - _ => unreachable!() - } + IFACE_RT.clone().unwrap() } }