Skip to content

Commit

Permalink
Added missing memory orderings for atomic types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazax-hun committed Jul 23, 2013
1 parent 0a5d1a1 commit 1ce1411
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/libstd/unstable/atomics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ pub struct AtomicOption<T> {
}

pub enum Ordering {
Relaxed,
Release,
Acquire,
AcqRel,
SeqCst
}

Expand Down Expand Up @@ -318,6 +320,7 @@ pub unsafe fn atomic_store<T>(dst: &mut T, val: T, order:Ordering) {

match order {
Release => intrinsics::atomic_store_rel(dst, val),
Relaxed => intrinsics::atomic_store_relaxed(dst, val),
_ => intrinsics::atomic_store(dst, val)
}
}
Expand All @@ -328,6 +331,7 @@ pub unsafe fn atomic_load<T>(dst: &T, order:Ordering) -> T {

cast::transmute(match order {
Acquire => intrinsics::atomic_load_acq(dst),
Relaxed => intrinsics::atomic_load_relaxed(dst),
_ => intrinsics::atomic_load(dst)
})
}
Expand All @@ -340,6 +344,8 @@ pub unsafe fn atomic_swap<T>(dst: &mut T, val: T, order: Ordering) -> T {
cast::transmute(match order {
Acquire => intrinsics::atomic_xchg_acq(dst, val),
Release => intrinsics::atomic_xchg_rel(dst, val),
AcqRel => intrinsics::atomic_xchg_acqrel(dst, val),
Relaxed => intrinsics::atomic_xchg_relaxed(dst, val),
_ => intrinsics::atomic_xchg(dst, val)
})
}
Expand All @@ -353,6 +359,8 @@ pub unsafe fn atomic_add<T>(dst: &mut T, val: T, order: Ordering) -> T {
cast::transmute(match order {
Acquire => intrinsics::atomic_xadd_acq(dst, val),
Release => intrinsics::atomic_xadd_rel(dst, val),
AcqRel => intrinsics::atomic_xadd_acqrel(dst, val),
Relaxed => intrinsics::atomic_xadd_relaxed(dst, val),
_ => intrinsics::atomic_xadd(dst, val)
})
}
Expand All @@ -366,6 +374,8 @@ pub unsafe fn atomic_sub<T>(dst: &mut T, val: T, order: Ordering) -> T {
cast::transmute(match order {
Acquire => intrinsics::atomic_xsub_acq(dst, val),
Release => intrinsics::atomic_xsub_rel(dst, val),
AcqRel => intrinsics::atomic_xsub_acqrel(dst, val),
Relaxed => intrinsics::atomic_xsub_relaxed(dst, val),
_ => intrinsics::atomic_xsub(dst, val)
})
}
Expand All @@ -379,6 +389,8 @@ pub unsafe fn atomic_compare_and_swap<T>(dst:&mut T, old:T, new:T, order: Orderi
cast::transmute(match order {
Acquire => intrinsics::atomic_cxchg_acq(dst, old, new),
Release => intrinsics::atomic_cxchg_rel(dst, old, new),
AcqRel => intrinsics::atomic_cxchg_acqrel(dst, old, new),
Relaxed => intrinsics::atomic_cxchg_relaxed(dst, old, new),
_ => intrinsics::atomic_cxchg(dst, old, new),
})
}
Expand Down

5 comments on commit 1ce1411

@bors
Copy link
Contributor

@bors bors commented on 1ce1411 Jul 24, 2013

Choose a reason for hiding this comment

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

saw approval from bblum
at Xazax-hun@1ce1411

@bors
Copy link
Contributor

@bors bors commented on 1ce1411 Jul 24, 2013

Choose a reason for hiding this comment

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

merging Xazax-hun/rust/master = 1ce1411 into auto

@bors
Copy link
Contributor

@bors bors commented on 1ce1411 Jul 24, 2013

Choose a reason for hiding this comment

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

Xazax-hun/rust/master = 1ce1411 merged ok, testing candidate = 5102853

@bors
Copy link
Contributor

@bors bors commented on 1ce1411 Jul 24, 2013

Choose a reason for hiding this comment

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

fast-forwarding master to auto = 5102853

Please sign in to comment.