From 00aee05f569ed21401269cd6be0631ede9a54df4 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Fri, 2 Feb 2024 18:43:36 +0200 Subject: [PATCH] Remove `atomic` crate from dependencies --- Cargo.lock | 1 - Cargo.toml | 1 - src/main.rs | 17 +++++++---------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4769178..a66ff3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10552,7 +10552,6 @@ dependencies = [ "anyhow", "arc-swap", "async-trait", - "atomic", "bytesize", "clap 4.4.18", "dark-light", diff --git a/Cargo.toml b/Cargo.toml index 32c5d8d..681a5a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,6 @@ product-name = "Space Acres" anyhow = "1.0.79" arc-swap = "1.6.0" async-trait = "0.1.77" -atomic = "0.5.3" bytesize = "1.3.0" clap = { version = "4.4.18", features = ["derive"] } dark-light = "1.0.0" diff --git a/src/main.rs b/src/main.rs index 65b5647..a9c41ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ use crate::frontend::configuration::{ConfigurationInput, ConfigurationOutput, Co use crate::frontend::loading::{LoadingInput, LoadingView}; use crate::frontend::new_version::NewVersion; use crate::frontend::running::{RunningInput, RunningView}; -use atomic::Atomic; use clap::Parser; use duct::cmd; use file_rotate::compression::Compression; @@ -19,6 +18,7 @@ use file_rotate::{ContentLimit, FileRotate}; use futures::channel::mpsc; use futures::{select, FutureExt, SinkExt, StreamExt}; use gtk::prelude::*; +use parking_lot::Mutex; use relm4::prelude::*; use relm4::{Sender, ShutdownReceiver, RELM_THREADS}; use relm4_icons::icon_name; @@ -26,7 +26,6 @@ use std::future::Future; use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use std::process::{ExitCode, Termination}; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread::available_parallelism; use std::{env, fs, io, process}; @@ -167,7 +166,7 @@ impl StatusBarNotification { } struct AppInit { - exit_status_code: Arc>, + exit_status_code: Arc>, minimize_on_start: bool, } @@ -183,7 +182,7 @@ struct App { running_view: Controller, menu_popover: gtk::Popover, about_dialog: gtk::AboutDialog, - exit_status_code: Arc>, + exit_status_code: Arc>, // Stored here so `Drop` is called on this future as well, preventing exit until everything shuts down gracefully _background_tasks: Box>, } @@ -548,8 +547,7 @@ impl AsyncComponent for App { self.current_view = View::Loading; } AppInput::Restart => { - self.exit_status_code - .store(AppStatusCode::Restart, Ordering::Release); + *self.exit_status_code.lock() = AppStatusCode::Restart; relm4::main_application().quit(); } } @@ -684,8 +682,7 @@ impl App { self.process_backend_notification(notification); } AppCommandOutput::Restart => { - self.exit_status_code - .store(AppStatusCode::Restart, Ordering::Release); + *self.exit_status_code.lock() = AppStatusCode::Restart; relm4::main_application().quit(); } } @@ -818,14 +815,14 @@ impl Cli { } } - let exit_status_code = Arc::new(Atomic::new(AppStatusCode::Exit)); + let exit_status_code = Arc::new(Mutex::new(AppStatusCode::Exit)); app.run_async::(AppInit { exit_status_code: Arc::clone(&exit_status_code), minimize_on_start: self.startup, }); - let exit_status_code = exit_status_code.load(Ordering::Acquire); + let exit_status_code = *exit_status_code.lock(); info!( ?exit_status_code, "Exiting {} {}",