auto merge of #19835 : pythonesque/rust/add-unordered-intrinsic, r=thestinger

This corresponds to the JMM memory model's non-volatile reads and writes to shared variables.  It provides fairly weak guarantees, but prevents UB (specifically, you will never see a value that was not written _at some point_ to the provided location).  It is not part of the C++ memory model and is only legal to provide to LLVM for loads and stores (not fences, atomicrmw, etc.).

Valid uses of this ordering are things like racy counters where you don't care about the operation actually being atomic, just want to avoid UB.  It cannot be used for synchronization without additional memory barriers since unordered loads and stores may be reordered freely by the optimizer (this is the main way it differs from relaxed).

Because it is new to Rust and it provides so few guarantees, for now only the intrinsic is provided--this patch doesn't add it to any of the higher-level atomic wrappers.
This commit is contained in:
bors 2015-01-03 01:10:40 +00:00
commit a6b109723a
2 changed files with 3 additions and 0 deletions

View File

@ -74,10 +74,12 @@ extern "rust-intrinsic" {
pub fn atomic_load<T>(src: *const T) -> T;
pub fn atomic_load_acq<T>(src: *const T) -> T;
pub fn atomic_load_relaxed<T>(src: *const T) -> T;
pub fn atomic_load_unordered<T>(src: *const T) -> T;
pub fn atomic_store<T>(dst: *mut T, val: T);
pub fn atomic_store_rel<T>(dst: *mut T, val: T);
pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;

View File

@ -525,6 +525,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
llvm::SequentiallyConsistent
} else {
match split[2] {
"unordered" => llvm::Unordered,
"relaxed" => llvm::Monotonic,
"acq" => llvm::Acquire,
"rel" => llvm::Release,