about summary refs log tree commit diff
path: root/src/libstd/sync
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-04 14:41:36 -0800
committerbors <bors@rust-lang.org>2014-02-04 14:41:36 -0800
commitacb1ec0b6715a529e3f6a7053737d99f03971c27 (patch)
tree4adf75d9d4e95504240dad7c6531f66f84d6f92a /src/libstd/sync
parentef53b7a97c58f65ac6967dfc6d30a4354afa34a3 (diff)
parent4f462a05066ea4ddbe65d3033402e7c80247ddde (diff)
downloadrust-acb1ec0b6715a529e3f6a7053737d99f03971c27.tar.gz
rust-acb1ec0b6715a529e3f6a7053737d99f03971c27.zip
auto merge of #11230 : csherratt/rust/cow, r=alexcrichton
This allows patch adds a new arc type that allows for creation of copy-on-write data structures. The idea is that it is safe to mutate any data structure as long as it has only one reference to it. If there are multiple, it requires cloning of the data structure before mutation is possible.
Diffstat (limited to 'src/libstd/sync')
-rw-r--r--src/libstd/sync/arc.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libstd/sync/arc.rs b/src/libstd/sync/arc.rs
index 7b94a3acc2b..5c452018b9b 100644
--- a/src/libstd/sync/arc.rs
+++ b/src/libstd/sync/arc.rs
@@ -94,6 +94,14 @@ impl<T: Send> UnsafeArc<T> {
             return &(*self.data).data as *T;
         }
     }
+
+    /// checks if this is the only reference to the arc protected data
+    #[inline]
+    pub fn is_owned(&self) -> bool {
+        unsafe {
+            (*self.data).count.load(Relaxed) == 1
+        }
+    }
 }
 
 impl<T: Send> Clone for UnsafeArc<T> {