Skip to content

Commit

Permalink
Merge pull request #267 from dtolnay/constmutex
Browse files Browse the repository at this point in the history
Remove OnceLock around intra-process lock's mutex
  • Loading branch information
dtolnay committed May 4, 2024
2 parents 62b1543 + 95f8cdb commit b988835
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/flock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::fs::{self, File, OpenOptions};
use std::io;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex, MutexGuard, OnceLock, PoisonError};
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
use std::thread;
use std::time::{Duration, SystemTime};

static LOCK: OnceLock<Mutex<()>> = OnceLock::new();
static LOCK: Mutex<()> = Mutex::new(());

pub(crate) struct Lock {
intraprocess_guard: Guard,
Expand Down Expand Up @@ -42,11 +42,7 @@ impl Lock {

impl Guard {
fn acquire() -> Self {
Guard::Locked(
LOCK.get_or_init(|| Mutex::new(()))
.lock()
.unwrap_or_else(PoisonError::into_inner),
)
Guard::Locked(LOCK.lock().unwrap_or_else(PoisonError::into_inner))
}
}

Expand Down

0 comments on commit b988835

Please sign in to comment.