Skip to content

std: minor simplification to sync::deque. #14378

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

Merged
merged 1 commit into from
May 24, 2014
Merged
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
10 changes: 5 additions & 5 deletions src/libstd/sync/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use clone::Clone;
use iter::{range, Iterator};
use kinds::Send;
use kinds::marker;
use mem::{forget, min_align_of, size_of, transmute};
use mem::{forget, min_align_of, size_of, transmute, overwrite};
use ops::Drop;
use option::{Option, Some, None};
use owned::Box;
Expand Down Expand Up @@ -371,20 +371,20 @@ impl<T: Send> Buffer<T> {
// Apparently LLVM cannot optimize (foo % (1 << bar)) into this implicitly
fn mask(&self) -> int { (1 << self.log_size) - 1 }

unsafe fn elem(&self, i: int) -> *T { self.storage.offset(i & self.mask()) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diverges slightly from the original paper, but it's so small there's no need to revert it.


// This does not protect against loading duplicate values of the same cell,
// nor does this clear out the contents contained within. Hence, this is a
// very unsafe method which the caller needs to treat specially in case a
// race is lost.
unsafe fn get(&self, i: int) -> T {
ptr::read(self.storage.offset(i & self.mask()))
ptr::read(self.elem(i))
}

// Unsafe because this unsafely overwrites possibly uninitialized or
// initialized data.
unsafe fn put(&self, i: int, t: T) {
let ptr = self.storage.offset(i & self.mask());
ptr::copy_nonoverlapping_memory(ptr as *mut T, &t as *T, 1);
forget(t);
overwrite(self.elem(i) as *mut T, t);
}

// Again, unsafe because this has incredibly dubious ownership violations.
Expand Down