Skip to content

Commit

Permalink
Use SeqCst at places
Browse files Browse the repository at this point in the history
... TODO: Describe rationale ...
... TODO: Is that all that's needed? ...

Maybe a solution for #76.
  • Loading branch information
vorner committed Jul 21, 2022
1 parent f7f192d commit 6b644ff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/debt/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ impl Node {
// Acquire ‒ we want to make sure we read the correct version of data at the end of the
// pointer. Any write to the DEBT_HEAD is with Release.
//
// Furthermore, we need to see the newest version of the list in case we examine the debts
// - if a new one is added recently, we don't want a stale read -> SeqCst.
//
// Note that the other pointers in the chain never change and are *ordinary* pointers. The
// whole linked list is synchronized through the head.
let mut current = unsafe { LIST_HEAD.load(Acquire).as_ref() };
let mut current = unsafe { LIST_HEAD.load(SeqCst).as_ref() };
while let Some(node) = current {
let result = f(node);
if result.is_some() {
Expand Down Expand Up @@ -143,7 +146,7 @@ impl Node {
.in_use
// We claim a unique control over the generation and the right to write to slots if
// they are NO_DEPT
.compare_exchange(NODE_UNUSED, NODE_USED, Acquire, Relaxed)
.compare_exchange(NODE_UNUSED, NODE_USED, SeqCst, Relaxed)
.is_ok()
{
Some(node)
Expand All @@ -167,7 +170,10 @@ impl Node {
head, node,
// We need to release *the whole chain* here. For that, we need to
// acquire it first.
AcqRel, Relaxed, // Nothing changed, go next round of the loop.
//
// SeqCst because we need to make sure it is properly set "before" we do
// anything to the debts.
SeqCst, Relaxed, // Nothing changed, go next round of the loop.
) {
head = old;
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/strategy/hybrid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ impl<T: RefCnt> HybridProtection<T> {
// Try to get a debt slot. If not possible, fail.
let debt = node.new_fast(ptr as usize)?;

let confirm = storage.load(Acquire);
// Acquire to get the data.
//
// SeqCst to make sure the storage vs. the debt are well ordered.
let confirm = storage.load(SeqCst);
if ptr == confirm {
// Successfully got a debt
Some(unsafe { Self::new(ptr, Some(debt)) })
Expand Down

0 comments on commit 6b644ff

Please sign in to comment.