1
- use super :: FuturesUnordered ;
2
1
use super :: task:: Task ;
2
+ use super :: FuturesUnordered ;
3
3
use core:: marker:: PhantomData ;
4
4
use core:: pin:: Pin ;
5
5
use core:: sync:: atomic:: Ordering :: Relaxed ;
@@ -9,25 +9,25 @@ use core::sync::atomic::Ordering::Relaxed;
9
9
pub struct IterPinMut < ' a , Fut > {
10
10
pub ( super ) task : * const Task < Fut > ,
11
11
pub ( super ) len : usize ,
12
- pub ( super ) _marker : PhantomData < & ' a mut FuturesUnordered < Fut > >
12
+ pub ( super ) _marker : PhantomData < & ' a mut FuturesUnordered < Fut > > ,
13
13
}
14
14
15
15
#[ derive( Debug ) ]
16
16
/// Mutable iterator over all futures in the unordered set.
17
- pub struct IterMut < ' a , Fut : Unpin > ( pub ( super ) IterPinMut < ' a , Fut > ) ;
17
+ pub struct IterMut < ' a , Fut : Unpin > ( pub ( super ) IterPinMut < ' a , Fut > ) ;
18
18
19
19
#[ derive( Debug ) ]
20
20
/// Immutable iterator over all futures in the unordered set.
21
21
pub struct IterPinRef < ' a , Fut > {
22
22
pub ( super ) task : * const Task < Fut > ,
23
23
pub ( super ) len : usize ,
24
24
pub ( super ) pending_next_all : * mut Task < Fut > ,
25
- pub ( super ) _marker : PhantomData < & ' a FuturesUnordered < Fut > >
25
+ pub ( super ) _marker : PhantomData < & ' a FuturesUnordered < Fut > > ,
26
26
}
27
27
28
28
#[ derive( Debug ) ]
29
29
/// Immutable iterator over all the futures in the unordered set.
30
- pub struct Iter < ' a , Fut : Unpin > ( pub ( super ) IterPinRef < ' a , Fut > ) ;
30
+ pub struct Iter < ' a , Fut : Unpin > ( pub ( super ) IterPinRef < ' a , Fut > ) ;
31
31
32
32
impl < ' a , Fut > Iterator for IterPinMut < ' a , Fut > {
33
33
type Item = Pin < & ' a mut Fut > ;
@@ -85,10 +85,7 @@ impl<'a, Fut> Iterator for IterPinRef<'a, Fut> {
85
85
// `head_all` was initially read for this iterator implies acquire
86
86
// ordering for all previously inserted nodes (and we don't need to
87
87
// read `len_all` again for any other nodes).
88
- let next = ( * self . task ) . spin_next_all (
89
- self . pending_next_all ,
90
- Relaxed ,
91
- ) ;
88
+ let next = ( * self . task ) . spin_next_all ( self . pending_next_all , Relaxed ) ;
92
89
self . task = next;
93
90
self . len -= 1 ;
94
91
Some ( Pin :: new_unchecked ( future) )
@@ -115,3 +112,11 @@ impl<'a, Fut: Unpin> Iterator for Iter<'a, Fut> {
115
112
}
116
113
117
114
impl < Fut : Unpin > ExactSizeIterator for Iter < ' _ , Fut > { }
115
+
116
+ // SAFETY: we do nothing thread-local and there is no interior mutability,
117
+ // so the usual structural `Send`/`Sync` apply.
118
+ unsafe impl < Fut : Send > Send for IterPinRef < ' _ , Fut > { }
119
+ unsafe impl < Fut : Sync > Sync for IterPinRef < ' _ , Fut > { }
120
+
121
+ unsafe impl < Fut : Send > Send for IterPinMut < ' _ , Fut > { }
122
+ unsafe impl < Fut : Sync > Sync for IterPinMut < ' _ , Fut > { }
0 commit comments