Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee-Janggun committed Oct 18, 2023
1 parent 58cc84a commit 9940b70
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
7 changes: 3 additions & 4 deletions src/lock/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ impl<'s, L: RawLock, T> LockGuard<'s, L, T> {

#[cfg(test)]
pub mod tests {
use core::ops::Deref;

use std::thread::scope;

Expand All @@ -193,8 +192,8 @@ pub mod tests {
}
});

let mut d = d.lock();
d.sort();
assert_eq!(d.deref(), &(1..LENGTH).collect::<Vec<usize>>());
let mut d = d.into_inner();
d.sort_unstable();
assert_eq!(d, (1..LENGTH).collect::<Vec<usize>>());
}
}
4 changes: 1 addition & 3 deletions src/lock/mcslock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ impl RawLock for McsLock {
// SAFETY: `prev` is valid, so is not the initial pointer. Hence, it is a pointer from
// `swap()` by another thread's `lock()`, and that thread guarantees that `prev` will not be
// freed until this store is complete.
unsafe {
(*prev).next.store(node, Ordering::Release);
}
unsafe { (*prev).next.store(node, Ordering::Release) };

let backoff = Backoff::new();
// SAFETY: `node` was made valid above. Since other threads will not free `node`, it still
Expand Down
4 changes: 1 addition & 3 deletions src/lock/mcsparkinglock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ impl RawLock for McsParkingLock {
}

// SAFETY: See safety of McsLock::lock().
unsafe {
(*prev).next.store(node, Ordering::Release);
}
unsafe { (*prev).next.store(node, Ordering::Release) };

// SAFETY: See safety of McsLock::lock().
while unsafe { (*node).locked.load(Ordering::Acquire) } {
Expand Down
2 changes: 1 addition & 1 deletion src/lockfree/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Cursor<'g, K, V> {
}

// Manual implementation as deriving `Clone` leads to unnecessary trait bounds.
impl<'g, K, V> Clone for Cursor<'g, K, V> {
impl<K, V> Clone for Cursor<'_, K, V> {
fn clone(&self) -> Self {
Self {
prev: self.prev,
Expand Down
12 changes: 7 additions & 5 deletions src/lockfree/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ impl<T> Default for Queue<T> {
head: CachePadded::new(Atomic::null()),
tail: CachePadded::new(Atomic::null()),
};

// SAFETY: We are creating a new queue, hence have sole ownership of it.
let sentinel = Owned::new(Node {
data: MaybeUninit::uninit(),
next: Atomic::null(),
});
// SAFETY: We are creating a new queue, hence have sole ownership of it.
let sentinel = sentinel.into_shared(unsafe { unprotected() });
})
.into_shared(unsafe { unprotected() });

q.head.store(sentinel, Ordering::Relaxed);
q.tail.store(sentinel, Ordering::Relaxed);
q
Expand All @@ -67,8 +69,8 @@ impl<T> Queue<T> {
let new = Owned::new(Node {
data: MaybeUninit::new(t),
next: Atomic::null(),
});
let new = new.into_shared(guard);
})
.into_shared(guard);

loop {
// We push onto the tail, so we'll start optimistically by looking there first.
Expand Down

0 comments on commit 9940b70

Please sign in to comment.