// option. This file may not be copied, modified, or distributed
// except according to those terms.
-/*!
- * Concurrency-enabled mechanisms for sharing mutable and/or immutable state
- * between tasks.
- */
+#![stable]
+
+//! Concurrency-enabled mechanisms for sharing mutable and/or immutable state
+//! between tasks.
use core::atomics;
use core::clone::Clone;
/// }
/// ```
#[unsafe_no_drop_flag]
+#[stable]
pub struct Arc<T> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be
/// used to break cycles between `Arc` pointers.
#[unsafe_no_drop_flag]
+#[experimental = "Weak pointers may not belong in this module."]
pub struct Weak<T> {
// FIXME #12808: strange name to try to avoid interfering with
// field accesses of the contained type via Deref
impl<T: Share + Send> Arc<T> {
/// Create an atomically reference counted wrapper.
#[inline]
+ #[stable]
pub fn new(data: T) -> Arc<T> {
// Start the weak pointer count as 1 which is the weak pointer that's
// held by all the strong pointers (kinda), see std/rc.rs for more info
}
#[inline]
- fn inner<'a>(&'a self) -> &'a ArcInner<T> {
+ fn inner(&self) -> &ArcInner<T> {
// This unsafety is ok because while this arc is alive we're guaranteed
// that the inner pointer is valid. Furthermore, we know that the
// `ArcInner` structure itself is `Share` because the inner data is
/// Weak pointers will not keep the data alive. Once all strong references
/// to the underlying data have been dropped, the data itself will be
/// destroyed.
+ #[experimental = "Weak pointers may not belong in this module."]
pub fn downgrade(&self) -> Weak<T> {
// See the clone() impl for why this is relaxed
self.inner().weak.fetch_add(1, atomics::Relaxed);
}
}
-#[unstable]
+#[unstable = "waiting on stability of Clone"]
impl<T: Share + Send> Clone for Arc<T> {
/// Duplicate an atomically reference counted wrapper.
///
}
}
+#[experimental = "Deref is experimental."]
impl<T: Send + Share> Deref<T> for Arc<T> {
#[inline]
- fn deref<'a>(&'a self) -> &'a T {
+ fn deref(&self) -> &T {
&self.inner().data
}
}
/// data is cloned if the reference count is greater than one.
#[inline]
#[experimental]
- pub fn make_unique<'a>(&'a mut self) -> &'a mut T {
+ pub fn make_unique(&mut self) -> &mut T {
// Note that we hold a strong reference, which also counts as
// a weak reference, so we only clone if there is an
// additional reference of either kind.
}
#[unsafe_destructor]
+#[experimental = "waiting on stability of Drop"]
impl<T: Share + Send> Drop for Arc<T> {
fn drop(&mut self) {
// This structure has #[unsafe_no_drop_flag], so this drop glue may run
}
}
+#[experimental = "Weak pointers may not belong in this module."]
impl<T: Share + Send> Weak<T> {
/// Attempts to upgrade this weak reference to a strong reference.
///
}
#[inline]
- fn inner<'a>(&'a self) -> &'a ArcInner<T> {
+ fn inner(&self) -> &ArcInner<T> {
// See comments above for why this is "safe"
unsafe { &*self._ptr }
}
}
-#[unstable]
+#[experimental = "Weak pointers may not belong in this module."]
impl<T: Share + Send> Clone for Weak<T> {
#[inline]
fn clone(&self) -> Weak<T> {
}
#[unsafe_destructor]
+#[experimental = "Weak pointers may not belong in this module."]
impl<T: Share + Send> Drop for Weak<T> {
fn drop(&mut self) {
// see comments above for why this check is here