Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Mar 30, 2024
1 parent 2fdcb0c commit 1a634fc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
10 changes: 6 additions & 4 deletions serial_test/src/parallel_code_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ use crate::code_lock::{check_new_key, global_locks};
use futures::FutureExt;
use std::panic;

fn get_locks(
names: Vec<&str>,
) -> Vec<crate::code_lock::UniqueReentrantMutex> {
fn get_locks(names: Vec<&str>) -> Vec<crate::code_lock::UniqueReentrantMutex> {
names
.into_iter()
.map(|name| {
check_new_key(name);
global_locks().get(name).expect("key to be set").get().clone()
global_locks()
.get(name)
.expect("key to be set")
.get()
.clone()
})
.collect::<Vec<_>>()
}
Expand Down
23 changes: 13 additions & 10 deletions serial_test/src/rwlock.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use parking_lot::{Condvar, Mutex, ReentrantMutex, ReentrantMutexGuard};
use std::{sync::Arc, time::Duration};
#[cfg(feature = "logging")]
use log::debug;
use parking_lot::{Condvar, Mutex, ReentrantMutex, ReentrantMutexGuard};
use std::{sync::Arc, time::Duration};

struct LockState {
parallels: u32,
Expand All @@ -18,7 +18,7 @@ pub(crate) struct Locks {
arc: Arc<LockData>,
// Name we're locking for (mostly test usage)
#[cfg(feature = "logging")]
pub(crate) name: String
pub(crate) name: String,
}

pub(crate) struct MutexGuardWrapper<'a> {
Expand All @@ -44,7 +44,7 @@ impl Locks {
serial: Default::default(),
}),
#[cfg(feature = "logging")]
name: name.to_owned()
name: name.to_owned(),
}
}

Expand All @@ -55,7 +55,7 @@ impl Locks {

pub fn serial(&self) -> MutexGuardWrapper {
#[cfg(feature = "logging")]
debug!("Get serial lock '{}'", self.name);
debug!("Get serial lock '{}'", self.name);
let mut lock_state = self.arc.mutex.lock();
loop {
#[cfg(feature = "logging")]
Expand All @@ -65,14 +65,14 @@ impl Locks {
let possible_serial_lock = self.arc.serial.try_lock();
if let Some(serial_lock) = possible_serial_lock {
#[cfg(feature = "logging")]
debug!("Got serial '{}'", self.name);
debug!("Got serial '{}'", self.name);
return MutexGuardWrapper {
mutex_guard: serial_lock,
locks: self.clone(),
};
} else {
#[cfg(feature = "logging")]
debug!("Someone else has serial '{}'", self.name);
debug!("Someone else has serial '{}'", self.name);
}
}

Expand All @@ -88,7 +88,10 @@ impl Locks {
let mut lock_state = self.arc.mutex.lock();
loop {
#[cfg(feature = "logging")]
debug!("Parallel, existing {} '{}'", lock_state.parallels, self.name);
debug!(
"Parallel, existing {} '{}'",
lock_state.parallels, self.name
);
if lock_state.parallels > 0 {
// fast path, as someone else already has it locked
lock_state.parallels += 1;
Expand All @@ -98,7 +101,7 @@ impl Locks {
let possible_serial_lock = self.arc.serial.try_lock();
if possible_serial_lock.is_some() {
#[cfg(feature = "logging")]
debug!("Parallel first '{}'", self.name);
debug!("Parallel first '{}'", self.name);
// We now know no-one else has the serial lock, so we can add to parallel
lock_state.parallels = 1; // Had to have been 0 before, as otherwise we'd have hit the fast path
return;
Expand All @@ -114,7 +117,7 @@ impl Locks {

pub fn end_parallel(&self) {
#[cfg(feature = "logging")]
debug!("End parallel");
debug!("End parallel");
let mut lock_state = self.arc.mutex.lock();
assert!(lock_state.parallels > 0);
lock_state.parallels -= 1;
Expand Down
6 changes: 5 additions & 1 deletion serial_test/src/serial_code_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ macro_rules! core_internal {
.into_iter()
.map(|name| {
check_new_key(name);
global_locks().get(name).expect("key to be set").get().clone()
global_locks()
.get(name)
.expect("key to be set")
.get()
.clone()
})
.collect();
let _guards: Vec<_> = unlocks.iter().map(|unlock| unlock.lock()).collect();
Expand Down
2 changes: 1 addition & 1 deletion serial_test_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
//! fn main() {}
//! ```

use log::info;
#[cfg(test)]
use serial_test::{parallel, serial};
use std::{
Expand All @@ -45,7 +46,6 @@ use std::{
thread,
time::Duration,
};
use log::info;

static LOCK: AtomicUsize = AtomicUsize::new(0);

Expand Down

0 comments on commit 1a634fc

Please sign in to comment.