From 08f619bc229e954a0bb331121bbf8e9677bf7830 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 21 Dec 2024 15:58:07 +0100 Subject: [PATCH] inputd: Remove usage of Arc for Vt Storing the vt index instead of a direct reference to the vt is just as easy. --- inputd/src/main.rs | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/inputd/src/main.rs b/inputd/src/main.rs index 0062e68b2b..928b8531e8 100644 --- a/inputd/src/main.rs +++ b/inputd/src/main.rs @@ -15,7 +15,6 @@ use std::collections::BTreeMap; use std::fs::File; use std::os::fd::AsRawFd; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Arc; use inputd::{Cmd, VtActivate}; @@ -59,15 +58,12 @@ struct Vt { } impl Vt { - fn new(display: D, index: usize) -> Arc - where - D: Into, - { - Arc::new(Self { + fn new(display: impl Into, index: usize) -> Self { + Self { display: display.into(), inner: spin::Once::new(), index, - }) + } } fn inner(&self) -> &Mutex { @@ -84,9 +80,9 @@ struct InputScheme { next_id: AtomicUsize, next_vt_id: AtomicUsize, - vts: BTreeMap>, + vts: BTreeMap, super_key: bool, - active_vt: Option>, + active_vt: Option, pending_activate: Option, has_new_events: bool, @@ -272,7 +268,7 @@ impl SchemeMut for InputScheme { }, EventOption::Resize(resize_event) => { - let active_vt = self.active_vt.as_ref().unwrap(); + let active_vt = &self.vts[&self.active_vt.unwrap()]; let mut vt_inner = active_vt.inner().lock(); inputd::send_comand( @@ -292,13 +288,13 @@ impl SchemeMut for InputScheme { } if let Some(new_active) = new_active_opt { - if new_active == self.active_vt.as_ref().unwrap().index { + if new_active == self.vts[&self.active_vt.unwrap()].index { continue 'out; } - if let Some(new_active) = self.vts.get(&new_active).cloned() { + if let Some(new_active) = self.vts.get(&new_active) { { - let active_vt = self.active_vt.as_ref().unwrap(); + let active_vt = &self.vts[&self.active_vt.unwrap()]; let mut vt_inner = active_vt.inner().lock(); inputd::send_comand( @@ -315,7 +311,7 @@ impl SchemeMut for InputScheme { vt: new_active.index, }, )?; - self.active_vt = Some(new_active.clone()); + self.active_vt = Some(new_active.index); } else { log::warn!("inputd: switch to non-existent VT #{new_active} was requested"); } @@ -324,7 +320,7 @@ impl SchemeMut for InputScheme { assert!(handle.is_producer()); - let active_vt = self.active_vt.as_ref().unwrap(); + let active_vt = self.active_vt.unwrap(); for handle in self.handles.values_mut() { match handle { Handle::Consumer { @@ -333,7 +329,7 @@ impl SchemeMut for InputScheme { vt, .. } => { - if *vt != active_vt.index { + if *vt != active_vt { continue; } @@ -412,7 +408,7 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> { log::error!("inputd: failed to activate VT #{}: {err}", vt.index) } - scheme.active_vt = Some(vt.clone()); + scheme.active_vt = Some(vt.index); } if !scheme.has_new_events { @@ -431,11 +427,11 @@ fn deamon(deamon: redox_daemon::Daemon) -> anyhow::Result<()> { continue; } - let active_vt = scheme.active_vt.as_ref().unwrap(); + let active_vt = scheme.active_vt.unwrap(); // The activate VT is not the same as the VT that the consumer is listening to // for events. - if active_vt.index != *vt { + if active_vt != *vt { continue; }