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;
mod task;
pub use task::AtomicWaker;
pub(crate) use task::AtomicWaker;
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
/// `wake`.
pub struct AtomicWaker {
pub(crate) struct AtomicWaker {
state: AtomicUsize,
waker: CausalCell<Option<Waker>>,
}
@ -132,7 +132,7 @@ const WAKING: usize = 0b10;
impl AtomicWaker {
/// Create an `AtomicWaker`
pub fn new() -> AtomicWaker {
pub(crate) fn new() -> AtomicWaker {
AtomicWaker {
state: AtomicUsize::new(WAITING),
waker: CausalCell::new(None),
@ -142,7 +142,8 @@ impl AtomicWaker {
/// Registers the current waker to be notified on calls to `wake`.
///
/// 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);
}
@ -161,7 +162,7 @@ impl AtomicWaker {
/// 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,
/// 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);
}
@ -238,7 +239,7 @@ impl AtomicWaker {
/// Wakes the task that last called `register`.
///
/// If `register` has not been called yet, then this does nothing.
pub fn wake(&self) {
pub(crate) fn wake(&self) {
debug!(" + wake");
if let Some(waker) = self.take_waker() {
waker.wake();
@ -247,7 +248,7 @@ impl AtomicWaker {
/// Attempts to take the `Waker` value out of the `AtomicWaker` with the
/// 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");
// AcqRel ordering is used in order to acquire the value of the `waker`
// cell as well as to establish a `release` ordering with whatever

View File

@ -1,4 +1,4 @@
//! Thread-safe task notification primitives.
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 tokio::sync::AtomicWaker;
use crate::sync::AtomicWaker;
use tokio_test::task;
use std::task::Waker;

View File

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