[code] Mutex -> RwLock
This commit is contained in:
@ -10,7 +10,7 @@ use s2n_quic::{Client as QuicClient, Connection, client::Connect, provider::limi
|
||||
use tokio::{
|
||||
io::AsyncWriteExt,
|
||||
sync::{
|
||||
Mutex,
|
||||
RwLock,
|
||||
mpsc::{UnboundedReceiver, UnboundedSender},
|
||||
},
|
||||
};
|
||||
@ -162,7 +162,7 @@ async fn download_game_files(
|
||||
}
|
||||
|
||||
struct Ctx {
|
||||
game_dir: Arc<Mutex<Option<String>>>,
|
||||
game_dir: Arc<RwLock<Option<String>>>,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
@ -181,7 +181,7 @@ pub async fn run(
|
||||
|
||||
// client context
|
||||
let ctx = Ctx {
|
||||
game_dir: Arc::new(Mutex::new(None)),
|
||||
game_dir: Arc::new(RwLock::new(None)),
|
||||
};
|
||||
|
||||
loop {
|
||||
@ -230,7 +230,7 @@ pub async fn run(
|
||||
continue;
|
||||
}
|
||||
ClientCommand::SetGameDir(game_dir) => {
|
||||
*ctx.game_dir.lock().await = Some(game_dir.clone());
|
||||
*ctx.game_dir.write().await = Some(game_dir.clone());
|
||||
continue;
|
||||
}
|
||||
ClientCommand::DownloadGameFiles {
|
||||
@ -239,7 +239,7 @@ pub async fn run(
|
||||
} => {
|
||||
log::info!("got ClientCommand::DownloadGameFiles");
|
||||
|
||||
let games_folder = { ctx.game_dir.lock().await.clone() };
|
||||
let games_folder = { ctx.game_dir.read().await.clone() };
|
||||
if let Some(games_folder) = games_folder {
|
||||
let tx_notify_ui = tx_notify_ui.clone();
|
||||
tokio::task::spawn(async move {
|
||||
@ -344,7 +344,7 @@ pub async fn run(
|
||||
file_descriptions.len()
|
||||
);
|
||||
|
||||
let games_folder = { ctx.game_dir.lock().await.clone() };
|
||||
let games_folder = { ctx.game_dir.read().await.clone() };
|
||||
|
||||
match games_folder {
|
||||
Some(games_folder) => {
|
||||
|
Reference in New Issue
Block a user