about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJames Miller <james@aatch.net>2013-07-28 19:48:16 +1200
committerJames Miller <james@aatch.net>2013-07-28 20:26:49 +1200
commit4a1a0fbed5a57958eb7b658bbe3e5257872ae99f (patch)
treefa6f345707b41d6928fc48d30bec705c559c0736 /src/libstd
parent9325535b41fa5a7cfac697e86ae86bd1384542e6 (diff)
downloadrust-4a1a0fbed5a57958eb7b658bbe3e5257872ae99f.tar.gz
rust-4a1a0fbed5a57958eb7b658bbe3e5257872ae99f.zip
Add an atomic fence intrinsic
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/unstable/atomics.rs27
-rw-r--r--src/libstd/unstable/intrinsics.rs9
2 files changed, 36 insertions, 0 deletions
diff --git a/src/libstd/unstable/atomics.rs b/src/libstd/unstable/atomics.rs
index 712c32d2436..8b57da32bbd 100644
--- a/src/libstd/unstable/atomics.rs
+++ b/src/libstd/unstable/atomics.rs
@@ -569,6 +569,33 @@ pub unsafe fn atomic_umin<T>(dst: &mut T, val: T, order: Ordering) -> T {
     })
 }
 
+/**
+ * An atomic fence.
+ *
+ * A fence 'A' which has `Release` ordering semantics, synchronizes with a
+ * fence 'B' with (at least) `Aquire` semantics, if and only if there exists
+ * atomic operations X and Y, bother operating on some atomic object 'M' such
+ * that A is sequenced before X, Y is synchronized before B and Y obsevers
+ * the change to M. This provides a happens-before dependence between A and B.
+ *
+ * Atomic operations with `Release` or `Acquire` semantics can also synchronize
+ * with a fence.
+ *
+ * A fence with has `SeqCst` ordering, in addition to having both `Acquire` and
+ * `Release` semantics, participates in the global program order of the other
+ * `SeqCst` operations and/or fences.
+ *
+ * Accepts `Acquire`, `Release`, `AcqRel` and `SeqCst` orderings.
+ */
+#[inline] #[cfg(not(stage0))]
+pub fn fence(order: Ordering) {
+    match order {
+        Acquire => intrinsics::atomic_fence_acq(),
+        Release => intrinsics::atomic_fence_rel(),
+        AcqRel  => intrinsics::atomic_fence_rel(),
+        _       => intrinsics::atomic_fence(),
+    }
+}
 
 #[cfg(test)]
 mod test {
diff --git a/src/libstd/unstable/intrinsics.rs b/src/libstd/unstable/intrinsics.rs
index 76958fa333f..655ede6b4eb 100644
--- a/src/libstd/unstable/intrinsics.rs
+++ b/src/libstd/unstable/intrinsics.rs
@@ -256,6 +256,15 @@ extern "rust-intrinsic" {
     pub fn atomic_umax_acqrel(dst: &mut int, src: int) -> int;
     pub fn atomic_umax_relaxed(dst: &mut int, src: int) -> int;
 
+    #[cfg(not(stage0))]
+    pub fn atomic_fence();
+    #[cfg(not(stage0))]
+    pub fn atomic_fence_acq();
+    #[cfg(not(stage0))]
+    pub fn atomic_fence_rel();
+    #[cfg(not(stage0))]
+    pub fn atomic_fence_acqrel();
+
     /// The size of a type in bytes.
     ///
     /// This is the exact number of bytes in memory taken up by a