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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 28 additions and 20 deletions

View File

@ -35,4 +35,4 @@ env_logger = { version = "0.5", default-features = false }
pin-utils = "0.1.0-alpha.4"
tokio = { version = "*", path = "../tokio" }
tokio-test = { version = "0.2.0", path = "../tokio-test" }
loom = { git = "https://github.com/carllerche/loom", features = ["futures"] }
loom = { version = "0.2.0", features = ["futures"] }

View File

@ -1,4 +1,4 @@
pub(crate) mod futures {
pub(crate) mod future {
pub(crate) use crate::task::AtomicWaker;
}

View File

@ -1,6 +1,6 @@
use super::list;
use crate::loom::{
futures::AtomicWaker,
future::AtomicWaker,
sync::atomic::AtomicUsize,
sync::{Arc, CausalCell},
};

View File

@ -9,7 +9,7 @@
//! `Pending`. The task is woken once a permit becomes available.
use crate::loom::{
futures::AtomicWaker,
future::AtomicWaker,
sync::{
atomic::{AtomicPtr, AtomicUsize},
CausalCell,

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;

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]

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()

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;

View File

@ -5,6 +5,7 @@
//! library's prelude you'll have to do so manually:
//!
//! ```
//! # #![allow(warnings)]
//! use tokio::prelude::*;
//! ```
//!