From 8ae35f5b01ed7353b5f035a9a604140ee0f7cdbf Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 11 Aug 2019 20:39:22 -0700 Subject: [PATCH] Arc -> Rc for macos --- window/src/os/macos/connection.rs | 14 +++++++------- window/src/os/macos/window.rs | 21 +++++++++++---------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/window/src/os/macos/connection.rs b/window/src/os/macos/connection.rs index 0e87e69e1..851454820 100644 --- a/window/src/os/macos/connection.rs +++ b/window/src/os/macos/connection.rs @@ -3,33 +3,33 @@ use cocoa::base::{id, nil}; use failure::Fallible; use objc::*; use std::cell::RefCell; -use std::sync::Arc; +use std::rc::Rc; pub struct Connection { ns_app: id, } thread_local! { - static CONN: RefCell>> = RefCell::new(None); + static CONN: RefCell>> = RefCell::new(None); } impl Connection { - pub fn get() -> Option> { + pub fn get() -> Option> { let mut res = None; CONN.with(|m| { if let Some(mux) = &*m.borrow() { - res = Some(Arc::clone(mux)); + res = Some(Rc::clone(mux)); } }); res } - pub fn init() -> Fallible> { + pub fn init() -> Fallible> { unsafe { let ns_app = NSApp(); ns_app.setActivationPolicy_(NSApplicationActivationPolicyRegular); - let conn = Arc::new(Self { ns_app }); - CONN.with(|m| *m.borrow_mut() = Some(Arc::clone(&conn))); + let conn = Rc::new(Self { ns_app }); + CONN.with(|m| *m.borrow_mut() = Some(Rc::clone(&conn))); Ok(conn) } } diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index cc5ee5deb..bcd34c3b6 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -14,8 +14,9 @@ use objc::declare::ClassDecl; use objc::rc::{StrongPtr, WeakPtr}; use objc::runtime::{Class, Object, Sel}; use objc::*; +use std::cell::RefCell; use std::ffi::c_void; -use std::sync::{Arc, Mutex}; +use std::rc::Rc; pub struct Window { window: StrongPtr, @@ -46,7 +47,7 @@ impl Window { NSSize::new(width as f64, height as f64), ); - let inner = Arc::new(Mutex::new(Inner { + let inner = Rc::new(RefCell::new(Inner { callbacks, view_id: None, })); @@ -98,7 +99,7 @@ impl Drop for Inner { const CLS_NAME: &str = "WezTermWindowView"; struct WindowView { - inner: Arc>, + inner: Rc>, } impl Drop for WindowView { @@ -174,7 +175,7 @@ impl<'a> PaintContext for MacGraphicsContext<'a> { impl WindowView { fn view_id(&self) -> id { - let inner = self.inner.lock().unwrap(); + let inner = self.inner.borrow_mut(); inner.view_id.as_ref().map(|w| *w.load()).unwrap_or(nil) } @@ -220,7 +221,7 @@ impl WindowView { } if let Some(this) = Self::get_this(this) { - if this.inner.lock().unwrap().callbacks.can_close() { + if this.inner.borrow_mut().callbacks.can_close() { YES } else { NO @@ -239,7 +240,7 @@ impl WindowView { eprintln!("window_will_close"); if let Some(this) = Self::get_this(this) { // Advise the window of its impending death - this.inner.lock().unwrap().callbacks.destroy(); + this.inner.borrow_mut().callbacks.destroy(); } // Release and zero out the inner member @@ -255,7 +256,7 @@ impl WindowView { if let Some(this) = Self::get_this(this) { let mut ctx = MacGraphicsContext { buffer: &mut im }; - this.inner.lock().unwrap().callbacks.paint(&mut ctx); + this.inner.borrow_mut().callbacks.paint(&mut ctx); } let cg_image = BitmapRef::with_image(&im); @@ -285,15 +286,15 @@ impl WindowView { } } - fn alloc(inner: &Arc>) -> Fallible { + fn alloc(inner: &Rc>) -> Fallible { let cls = Self::get_class(); let view_id: StrongPtr = unsafe { StrongPtr::new(msg_send![cls, new]) }; - inner.lock().unwrap().view_id.replace(view_id.weak()); + inner.borrow_mut().view_id.replace(view_id.weak()); let view = Box::into_raw(Box::new(Self { - inner: Arc::clone(&inner), + inner: Rc::clone(&inner), })); unsafe {