From 6b43f6139464dd07b7dddd5ffe787c99b2cc8317 Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Sun, 9 Dec 2018 17:05:22 +0100 Subject: [PATCH] App: store weak pointer to AppOp --- fractal-gtk/src/app/mod.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fractal-gtk/src/app/mod.rs b/fractal-gtk/src/app/mod.rs index eaeb06ff..5cff24a9 100644 --- a/fractal-gtk/src/app/mod.rs +++ b/fractal-gtk/src/app/mod.rs @@ -8,7 +8,7 @@ use std::ops; use std::rc::{Rc, Weak}; use std::sync::mpsc::channel; use std::sync::mpsc::{Receiver, Sender}; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, Mutex, Weak as SyncWeak}; use appop::AppOp; use backend::BKResponse; @@ -20,7 +20,7 @@ use uibuilder; mod connect; -static mut OP: Option>> = None; +static mut OP: Option>> = None; #[macro_export] macro_rules! APPOP { ($fn: ident, ($($x:ident),*) ) => {{ @@ -134,7 +134,7 @@ impl App { let op = Arc::new(Mutex::new(AppOp::new(ui.clone(), apptx))); unsafe { - OP = Some(op.clone()); + OP = Some(Arc::downgrade(&op)); } backend_loop(rx); @@ -211,11 +211,6 @@ impl App { // Legazy function to get AppOp // This shouldn't be used in new code pub fn get_op() -> Option>> { - unsafe { - match OP { - Some(ref m) => Some(m.clone()), - None => None, - } - } + unsafe { OP.as_ref().and_then(|x| x.upgrade()) } } }