@@ -1006,15 +1006,13 @@ impl KVStoreSync for TestStore {
1006
1006
1007
1007
// A `Future` that returns the result only on the second poll.
1008
1008
pub ( crate ) struct TestStoreFuture < R > {
1009
- res : Mutex < Option < io:: Result < R > > > ,
1010
- first_poll : AtomicBool ,
1009
+ inner : Mutex < ( bool , Option < io:: Result < R > > ) > ,
1011
1010
}
1012
1011
1013
1012
impl < R > TestStoreFuture < R > {
1014
1013
fn new ( res : io:: Result < R > ) -> Self {
1015
- let res = Mutex :: new ( Some ( res) ) ;
1016
- let first_poll = AtomicBool :: new ( true ) ;
1017
- Self { res, first_poll }
1014
+ let inner = Mutex :: new ( ( true , Some ( res) ) ) ;
1015
+ Self { inner }
1018
1016
}
1019
1017
}
1020
1018
@@ -1023,10 +1021,13 @@ impl<R> Future for TestStoreFuture<R> {
1023
1021
fn poll (
1024
1022
self : Pin < & mut Self > , _cx : & mut core:: task:: Context < ' _ > ,
1025
1023
) -> core:: task:: Poll < Self :: Output > {
1026
- if self . first_poll . swap ( false , Ordering :: Relaxed ) {
1024
+ let mut inner_lock = self . inner . lock ( ) . unwrap ( ) ;
1025
+ let first_poll = & mut inner_lock. 0 ;
1026
+ if * first_poll {
1027
+ * first_poll = false ;
1027
1028
core:: task:: Poll :: Pending
1028
1029
} else {
1029
- if let Some ( res) = self . res . lock ( ) . unwrap ( ) . take ( ) {
1030
+ if let Some ( res) = inner_lock . 1 . take ( ) {
1030
1031
core:: task:: Poll :: Ready ( res)
1031
1032
} else {
1032
1033
unreachable ! ( "We should never poll more than twice" ) ;
0 commit comments