Skip to content

Commit 29b3698

Browse files
committed
Implement Sync/Send for ArcInner and Weak
1 parent 84a6684 commit 29b3698

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/liballoc/arc.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ pub struct Arc<T> {
117117
_ptr: *mut ArcInner<T>,
118118
}
119119

120+
unsafe impl<T: Sync + Send> Send for Arc<T> { }
121+
unsafe impl<T: Sync + Send> Sync for Arc<T> { }
122+
123+
120124
/// A weak pointer to an `Arc`.
121125
///
122126
/// Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles
@@ -129,16 +133,18 @@ pub struct Weak<T> {
129133
_ptr: *mut ArcInner<T>,
130134
}
131135

132-
unsafe impl<T: Sync + Send> Send for Arc<T> { }
133-
134-
unsafe impl<T: Sync + Send> Sync for Arc<T> { }
136+
unsafe impl<T: Sync + Send> Send for Weak<T> { }
137+
unsafe impl<T: Sync + Send> Sync for Weak<T> { }
135138

136139
struct ArcInner<T> {
137140
strong: atomic::AtomicUint,
138141
weak: atomic::AtomicUint,
139142
data: T,
140143
}
141144

145+
unsafe impl<T: Sync + Send> Send for ArcInner<T> {}
146+
unsafe impl<T: Sync + Send> Sync for ArcInner<T> {}
147+
142148
impl<T> Arc<T> {
143149
/// Constructs a new `Arc<T>`.
144150
///
@@ -591,6 +597,7 @@ mod tests {
591597
use std::str::Str;
592598
use std::sync::atomic;
593599
use std::task;
600+
use std::kinds::Send;
594601
use std::vec::Vec;
595602
use super::{Arc, Weak, weak_count, strong_count};
596603
use std::sync::Mutex;

0 commit comments

Comments
 (0)