make AtomicWaker private (#1782)

This commit is contained in:
Carl Lerche 2019-11-16 23:35:17 -08:00 committed by GitHub
parent b1d9e55487
commit c147be0437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 12 deletions

View File

@ -47,7 +47,7 @@ pub mod oneshot;
pub mod semaphore; pub mod semaphore;
mod task; mod task;
pub use task::AtomicWaker; pub(crate) use task::AtomicWaker;
pub mod watch; pub mod watch;

View File

@ -20,7 +20,7 @@ use std::task::Waker;
/// ///
/// A single `AtomicWaker` may be reused for any number of calls to `register` or /// A single `AtomicWaker` may be reused for any number of calls to `register` or
/// `wake`. /// `wake`.
pub struct AtomicWaker { pub(crate) struct AtomicWaker {
state: AtomicUsize, state: AtomicUsize,
waker: CausalCell<Option<Waker>>, waker: CausalCell<Option<Waker>>,
} }
@ -132,7 +132,7 @@ const WAKING: usize = 0b10;
impl AtomicWaker { impl AtomicWaker {
/// Create an `AtomicWaker` /// Create an `AtomicWaker`
pub fn new() -> AtomicWaker { pub(crate) fn new() -> AtomicWaker {
AtomicWaker { AtomicWaker {
state: AtomicUsize::new(WAITING), state: AtomicUsize::new(WAITING),
waker: CausalCell::new(None), waker: CausalCell::new(None),
@ -142,7 +142,8 @@ impl AtomicWaker {
/// Registers the current waker to be notified on calls to `wake`. /// Registers the current waker to be notified on calls to `wake`.
/// ///
/// This is the same as calling `register_task` with `task::current()`. /// This is the same as calling `register_task` with `task::current()`.
pub fn register(&self, waker: Waker) { #[cfg(feature = "io-driver")]
pub(crate) fn register(&self, waker: Waker) {
self.do_register(waker); self.do_register(waker);
} }
@ -161,7 +162,7 @@ impl AtomicWaker {
/// idea. Concurrent calls to `register` will attempt to register different /// idea. Concurrent calls to `register` will attempt to register different
/// tasks to be woken. One of the callers will win and have its task set, /// tasks to be woken. One of the callers will win and have its task set,
/// but there is no guarantee as to which caller will succeed. /// but there is no guarantee as to which caller will succeed.
pub fn register_by_ref(&self, waker: &Waker) { pub(crate) fn register_by_ref(&self, waker: &Waker) {
self.do_register(waker); self.do_register(waker);
} }
@ -238,7 +239,7 @@ impl AtomicWaker {
/// Wakes the task that last called `register`. /// Wakes the task that last called `register`.
/// ///
/// If `register` has not been called yet, then this does nothing. /// If `register` has not been called yet, then this does nothing.
pub fn wake(&self) { pub(crate) fn wake(&self) {
debug!(" + wake"); debug!(" + wake");
if let Some(waker) = self.take_waker() { if let Some(waker) = self.take_waker() {
waker.wake(); waker.wake();
@ -247,7 +248,7 @@ impl AtomicWaker {
/// Attempts to take the `Waker` value out of the `AtomicWaker` with the /// Attempts to take the `Waker` value out of the `AtomicWaker` with the
/// intention that the caller will wake the task later. /// intention that the caller will wake the task later.
pub fn take_waker(&self) -> Option<Waker> { pub(crate) fn take_waker(&self) -> Option<Waker> {
debug!(" + take_waker"); debug!(" + take_waker");
// AcqRel ordering is used in order to acquire the value of the `waker` // AcqRel ordering is used in order to acquire the value of the `waker`
// cell as well as to establish a `release` ordering with whatever // cell as well as to establish a `release` ordering with whatever

View File

@ -1,4 +1,4 @@
//! Thread-safe task notification primitives. //! Thread-safe task notification primitives.
mod atomic_waker; mod atomic_waker;
pub use self::atomic_waker::AtomicWaker; pub(crate) use self::atomic_waker::AtomicWaker;

View File

@ -1,6 +1,4 @@
#![warn(rust_2018_idioms)] use crate::sync::AtomicWaker;
use tokio::sync::AtomicWaker;
use tokio_test::task; use tokio_test::task;
use std::task::Waker; use std::task::Waker;

View File

@ -1,7 +1,17 @@
#![cfg(loom)] #[cfg(not(loom))]
mod atomic_waker;
#[cfg(loom)]
mod loom_atomic_waker; mod loom_atomic_waker;
#[cfg(loom)]
mod loom_list; mod loom_list;
#[cfg(loom)]
mod loom_mpsc; mod loom_mpsc;
#[cfg(loom)]
mod loom_oneshot; mod loom_oneshot;
#[cfg(loom)]
mod loom_semaphore; mod loom_semaphore;