Skip to content

Commit

Permalink
ref: use RwLock instead of Mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
Phill030 committed Sep 16, 2023
1 parent 52cd61b commit 59b4b70
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
net::SocketAddr,
process,
sync::{Arc, Mutex},
sync::{Arc, Mutex, RwLock},
time::Duration,
};

Expand All @@ -19,7 +19,7 @@ mod routes;
mod util;

lazy_static! {
pub static ref REVISIONS: Mutex<Vec<String>> = Mutex::new(vec![]);
pub static ref REVISIONS: RwLock<Vec<String>> = RwLock::new(vec![]);
}

#[allow(dead_code)]
Expand Down
2 changes: 1 addition & 1 deletion src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn get_revisions(
return Err(RATE_LIMIT.into_response());
}

let folders = match REVISIONS.lock() {
let folders = match REVISIONS.read() {
Ok(r) => r.clone(),
Err(why) => {
log::error!("Could not lock REVISIONS, {why}");
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub async fn explore_revisions() -> std::io::Result<()> {
}
}

let mut revisions = REVISIONS.lock().unwrap();
let mut revisions = REVISIONS.write().unwrap();
*revisions = revisions_vec;

Ok(())
Expand Down

0 comments on commit 59b4b70

Please sign in to comment.