Skip to content

Commit 3cafc79

Browse files
committed
Cleanup.
Closes #975
1 parent 5f1f3fd commit 3cafc79

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

homework/src/boc.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ pub unsafe trait CownPtrs {
241241
}
242242

243243
unsafe impl CownPtrs for () {
244-
type CownRefs<'l> = ()
244+
type CownRefs<'l>
245+
= ()
245246
where
246247
Self: 'l;
247248

@@ -253,7 +254,8 @@ unsafe impl CownPtrs for () {
253254
}
254255

255256
unsafe impl<T: Send + 'static, Ts: CownPtrs> CownPtrs for (CownPtr<T>, Ts) {
256-
type CownRefs<'l> = (&'l mut T, Ts::CownRefs<'l>)
257+
type CownRefs<'l>
258+
= (&'l mut T, Ts::CownRefs<'l>)
257259
where
258260
Self: 'l;
259261

@@ -270,7 +272,8 @@ unsafe impl<T: Send + 'static, Ts: CownPtrs> CownPtrs for (CownPtr<T>, Ts) {
270272
}
271273

272274
unsafe impl<T: Send + 'static> CownPtrs for Vec<CownPtr<T>> {
273-
type CownRefs<'l> = Vec<&'l mut T>
275+
type CownRefs<'l>
276+
= Vec<&'l mut T>
274277
where
275278
Self: 'l;
276279

homework/src/elim_stack/base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ pub struct ElimStack<T, S: Stack<T>> {
6868
// - 2: pop request
6969
// - 3: request acknowledged
7070
pub(crate) slots: [Atomic<S::PushReq>; ELIM_SIZE],
71-
_marker: PhantomData<T>,
7271
}
7372

7473
impl<T, S: Stack<T>> Default for ElimStack<T, S> {
7574
fn default() -> Self {
7675
Self {
7776
inner: Default::default(),
7877
slots: Default::default(),
79-
_marker: PhantomData,
8078
}
8179
}
8280
}

homework/src/hazard_pointer/hazard.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ impl Shield {
4545
/// means that this shield is validated.
4646
pub fn try_protect<T>(&self, pointer: *mut T, src: &AtomicPtr<T>) -> Result<(), *mut T> {
4747
self.set(pointer);
48-
Self::validate(pointer, src).map_err(|new| {
49-
self.clear();
50-
new
51-
})
48+
Self::validate(pointer, src).inspect_err(|_| self.clear())
5249
}
5350

5451
/// Get a protected pointer from `src`.

homework/src/list_set/optimistic_fine_grained.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ use std::cmp::Ordering::*;
22
use std::mem::{self, ManuallyDrop};
33
use std::sync::atomic::Ordering;
44

5-
use crate::ConcurrentSet;
65
use crossbeam_epoch::{pin, Atomic, Guard, Owned, Shared};
76
use cs431::lock::seqlock::{ReadGuard, SeqLock};
87

8+
use crate::ConcurrentSet;
9+
910
#[derive(Debug)]
1011
struct Node<T> {
1112
data: T,
@@ -92,7 +93,7 @@ pub struct Iter<'g, T> {
9293
impl<T> OptimisticFineGrainedListSet<T> {
9394
/// An iterator visiting all elements. `next()` returns `Some(Err(()))` when validation fails.
9495
/// In that case, the user must restart the iteration.
95-
pub fn iter<'g>(&'g self, guard: &'g Guard) -> Iter<'_, T> {
96+
pub fn iter<'g>(&'g self, guard: &'g Guard) -> Iter<'g, T> {
9697
Iter {
9798
cursor: ManuallyDrop::new(self.head(guard)),
9899
guard,

homework/tests/growable_array.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<V> ConcurrentMap<u32, V> for ArrayMap<V> {
6363
return Err(());
6464
}
6565
match slot.compare_exchange(curr, Shared::null(), AcqRel, Acquire, guard) {
66-
Ok(_) => Ok(unsafe { curr.deref() }.deref()),
66+
Ok(_) => Ok(unsafe { curr.deref() }),
6767
Err(_) => Err(()), // already removed
6868
}
6969
}
@@ -132,8 +132,11 @@ mod stack {
132132
pub(super) unsafe fn push_node<'g>(&self, n: Shared<'g, Node<T>>, guard: &'g Guard) {
133133
let mut head = self.head.load(Relaxed, guard);
134134
loop {
135+
// SAEFTY: as n is pused only once, and after the push, n is not used again, we are
136+
// the unique accessor of `n.next`. Hence non-atomic write is safe.
135137
unsafe { *n.deref().next.get() = head.as_raw() };
136138

139+
// TODO: Relaxed fine here? Might need release so that it syncs with `drop`?
137140
match self.head.compare_exchange(head, n, Relaxed, Relaxed, guard) {
138141
Ok(_) => break,
139142
Err(e) => head = e.current,

src/lock/api.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use core::ops::{Deref, DerefMut};
1212
pub unsafe trait RawLock: Default + Send + Sync {
1313
/// Raw lock's token type.
1414
///
15-
/// Send + Sync is needed to make LockGuard Send + Sync.
16-
type Token: Send + Sync;
15+
/// We don't enforce Send + Sync, as some locks may not satisfy it. Nessecary bounds will be
16+
/// auto-derived.
17+
type Token;
1718

1819
/// Acquires the raw lock.
1920
fn lock(&self) -> Self::Token;
@@ -49,6 +50,8 @@ pub struct Lock<L: RawLock, T> {
4950
}
5051

5152
// Send is automatically implemented for Lock.
53+
54+
// SATEFY: threads can only access `&mut T` via the lock, and `L` is `Sync`.
5255
unsafe impl<L: RawLock, T: Send> Sync for Lock<L, T> {}
5356

5457
impl<L: RawLock, T: Default> Default for Lock<L, T>
@@ -99,7 +102,7 @@ impl<L: RawTryLock, T> Lock<L, T> {
99102
}
100103

101104
/// A guard that holds the lock and dereferences the inner value.
102-
// Send/Sync are automatically implemented.
105+
// `Send` and `Sync` are automatically derived.
103106
#[derive(Debug)]
104107
pub struct LockGuard<'s, L: RawLock, T> {
105108
lock: &'s Lock<L, T>,

0 commit comments

Comments
 (0)