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() } }