1- use super :: FuturesUnordered ;
21use super :: task:: Task ;
2+ use super :: FuturesUnordered ;
33use core:: marker:: PhantomData ;
44use core:: pin:: Pin ;
55use core:: sync:: atomic:: Ordering :: Relaxed ;
@@ -9,25 +9,25 @@ use core::sync::atomic::Ordering::Relaxed;
99pub struct IterPinMut < ' a , Fut > {
1010 pub ( super ) task : * const Task < Fut > ,
1111 pub ( super ) len : usize ,
12- pub ( super ) _marker : PhantomData < & ' a mut FuturesUnordered < Fut > >
12+ pub ( super ) _marker : PhantomData < & ' a mut FuturesUnordered < Fut > > ,
1313}
1414
1515#[ derive( Debug ) ]
1616/// 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 > ) ;
1818
1919#[ derive( Debug ) ]
2020/// Immutable iterator over all futures in the unordered set.
2121pub struct IterPinRef < ' a , Fut > {
2222 pub ( super ) task : * const Task < Fut > ,
2323 pub ( super ) len : usize ,
2424 pub ( super ) pending_next_all : * mut Task < Fut > ,
25- pub ( super ) _marker : PhantomData < & ' a FuturesUnordered < Fut > >
25+ pub ( super ) _marker : PhantomData < & ' a FuturesUnordered < Fut > > ,
2626}
2727
2828#[ derive( Debug ) ]
2929/// 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 > ) ;
3131
3232impl < ' a , Fut > Iterator for IterPinMut < ' a , Fut > {
3333 type Item = Pin < & ' a mut Fut > ;
@@ -85,10 +85,7 @@ impl<'a, Fut> Iterator for IterPinRef<'a, Fut> {
8585 // `head_all` was initially read for this iterator implies acquire
8686 // ordering for all previously inserted nodes (and we don't need to
8787 // 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 ) ;
9289 self . task = next;
9390 self . len -= 1 ;
9491 Some ( Pin :: new_unchecked ( future) )
@@ -115,3 +112,11 @@ impl<'a, Fut: Unpin> Iterator for Iter<'a, Fut> {
115112}
116113
117114impl < 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