Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrong memory order #7

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl Ringbuf {
let ptr = self.metadata.consume_offset_ptr;

let atomic = unsafe { AtomicU32::from_ptr(ptr) };
atomic.load(Ordering::Relaxed)
atomic.load(Ordering::Acquire)
}

/// Get the produce offset which is the next write position in ringbuf.
Expand All @@ -304,7 +304,7 @@ impl Ringbuf {
let ptr = self.metadata.produce_offset_ptr;

let atomic = unsafe { AtomicU32::from_ptr(ptr) };
atomic.load(Ordering::Relaxed)
atomic.load(Ordering::Acquire)
}

/// Set the consume offset which is the next read position in ringbuf.
Expand Down Expand Up @@ -337,7 +337,7 @@ impl Ringbuf {
let atomic = unsafe { AtomicU32::from_ptr(ptr) };

let _ =
atomic.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |pre| {
atomic.fetch_update(Ordering::Release, Ordering::Acquire, |pre| {
Some((pre + len) % self.data_part_len as u32)
});
}
Expand All @@ -352,7 +352,7 @@ impl Ringbuf {
let atomic = unsafe { AtomicU32::from_ptr(ptr) };

let _ =
atomic.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |pre| {
atomic.fetch_update(Ordering::Release, Ordering::Acquire, |pre| {
Some((pre + len) % self.data_part_len as u32)
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/ringbuf/data_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ impl Header {
let ptr = self.busy_ptr;
let atomic = unsafe { AtomicU32::from_ptr(ptr) };

atomic.load(Ordering::Relaxed) == 1
atomic.load(Ordering::Acquire) == 1
}

fn set_busy(&self, busy: bool) {
let ptr = self.busy_ptr;
let atomic = unsafe { AtomicU32::from_ptr(ptr) };

if busy {
atomic.store(1, Ordering::Relaxed);
atomic.store(1, Ordering::Release);
} else {
atomic.store(0, Ordering::Relaxed);
atomic.store(0, Ordering::Release);
}
}

Expand Down
Loading