sync: track upstream loom changes (#1407)

This commit is contained in:
Carl Lerche
2019-08-07 23:24:22 -07:00
committed by GitHub
parent 962521f449
commit 2e69f2a7fd
9 changed files with 28 additions and 20 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ mod atomic_waker;
use crate::atomic_waker::AtomicWaker;
use futures_util::future::poll_fn;
use loom::futures::block_on;
use loom::future::block_on;
use loom::sync::atomic::AtomicUsize;
use loom::thread;
use std::sync::atomic::Ordering::Relaxed;
+1 -1
View File
@@ -19,7 +19,7 @@ mod mpsc;
mod semaphore;
use futures_util::future::poll_fn;
use loom::futures::block_on;
use loom::future::block_on;
use loom::thread;
#[test]
+20 -13
View File
@@ -5,11 +5,11 @@
#[allow(warnings)]
mod oneshot;
// use futures::{self, Async, Future};
use loom;
use loom::futures::{block_on, poll_future};
use loom::future::block_on;
use loom::thread;
use futures_util::future::poll_fn;
use std::task::Poll::{Pending, Ready};
#[test]
@@ -36,14 +36,19 @@ fn changing_rx_task() {
});
let rx = thread::spawn(move || {
match poll_future(&mut rx) {
let ready = block_on(poll_fn(|cx| match Pin::new(&mut rx).poll(cx) {
Ready(Ok(value)) => {
// ok
assert_eq!(1, value);
None
Ready(true)
}
Ready(Err(_)) => unimplemented!(),
Pending => Some(rx),
Pending => Ready(false),
}));
if ready {
None
} else {
Some(rx)
}
})
.join()
@@ -74,10 +79,11 @@ impl<'a> OnClose<'a> {
}
impl<'a> Future for OnClose<'a> {
type Output = ();
type Output = bool;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
self.get_mut().tx.poll_closed(cx)
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<bool> {
let res = self.get_mut().tx.poll_closed(cx);
Ready(res.is_ready())
}
}
@@ -91,11 +97,12 @@ fn changing_tx_task() {
});
let tx = thread::spawn(move || {
let t1 = poll_future(&mut OnClose::new(&mut tx));
let t1 = block_on(OnClose::new(&mut tx));
match t1 {
Ready(()) => None,
Pending => Some(tx),
if t1 {
None
} else {
Some(tx)
}
})
.join()
+1 -1
View File
@@ -11,7 +11,7 @@ use crate::semaphore::*;
use futures_core::ready;
use futures_util::future::poll_fn;
use loom::futures::block_on;
use loom::future::block_on;
use loom::thread;
use std::future::Future;
use std::pin::Pin;