Implement Sync/Send for ArcInner and Weak
This commit is contained in:
parent
84a6684c65
commit
29b3698f7f
@ -117,6 +117,10 @@ pub struct Arc<T> {
|
|||||||
_ptr: *mut ArcInner<T>,
|
_ptr: *mut ArcInner<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl<T: Sync + Send> Send for Arc<T> { }
|
||||||
|
unsafe impl<T: Sync + Send> Sync for Arc<T> { }
|
||||||
|
|
||||||
|
|
||||||
/// A weak pointer to an `Arc`.
|
/// A weak pointer to an `Arc`.
|
||||||
///
|
///
|
||||||
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles
|
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles
|
||||||
@ -129,9 +133,8 @@ pub struct Weak<T> {
|
|||||||
_ptr: *mut ArcInner<T>,
|
_ptr: *mut ArcInner<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<T: Sync + Send> Send for Arc<T> { }
|
unsafe impl<T: Sync + Send> Send for Weak<T> { }
|
||||||
|
unsafe impl<T: Sync + Send> Sync for Weak<T> { }
|
||||||
unsafe impl<T: Sync + Send> Sync for Arc<T> { }
|
|
||||||
|
|
||||||
struct ArcInner<T> {
|
struct ArcInner<T> {
|
||||||
strong: atomic::AtomicUint,
|
strong: atomic::AtomicUint,
|
||||||
@ -139,6 +142,9 @@ struct ArcInner<T> {
|
|||||||
data: T,
|
data: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl<T: Sync + Send> Send for ArcInner<T> {}
|
||||||
|
unsafe impl<T: Sync + Send> Sync for ArcInner<T> {}
|
||||||
|
|
||||||
impl<T> Arc<T> {
|
impl<T> Arc<T> {
|
||||||
/// Constructs a new `Arc<T>`.
|
/// Constructs a new `Arc<T>`.
|
||||||
///
|
///
|
||||||
@ -591,6 +597,7 @@ mod tests {
|
|||||||
use std::str::Str;
|
use std::str::Str;
|
||||||
use std::sync::atomic;
|
use std::sync::atomic;
|
||||||
use std::task;
|
use std::task;
|
||||||
|
use std::kinds::Send;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use super::{Arc, Weak, weak_count, strong_count};
|
use super::{Arc, Weak, weak_count, strong_count};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
Loading…
Reference in New Issue
Block a user