diff options
| author | bors <bors@rust-lang.org> | 2014-02-04 14:41:36 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-04 14:41:36 -0800 |
| commit | acb1ec0b6715a529e3f6a7053737d99f03971c27 (patch) | |
| tree | 4adf75d9d4e95504240dad7c6531f66f84d6f92a /src/libstd | |
| parent | ef53b7a97c58f65ac6967dfc6d30a4354afa34a3 (diff) | |
| parent | 4f462a05066ea4ddbe65d3033402e7c80247ddde (diff) | |
| download | rust-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')
| -rw-r--r-- | src/libstd/sync/arc.rs | 8 |
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> { |
