mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
chore: apply unreachable_pub and missing_debug_implementations to all crates (#1424)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-buf/0.2.0-alpha.1")]
|
||||
#![warn(
|
||||
missing_docs,
|
||||
missing_debug_implementations,
|
||||
unreachable_pub,
|
||||
rust_2018_idioms
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ pub struct Framed<T, U> {
|
||||
inner: FramedRead2<FramedWrite2<Fuse<T, U>>>,
|
||||
}
|
||||
|
||||
pub struct Fuse<T, U>(pub T, pub U);
|
||||
pub(crate) struct Fuse<T, U>(pub(crate) T, pub(crate) U);
|
||||
|
||||
impl<T, U> Framed<T, U>
|
||||
where
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct FramedRead<T, D> {
|
||||
inner: FramedRead2<Fuse<T, D>>,
|
||||
}
|
||||
|
||||
pub struct FramedRead2<T> {
|
||||
pub(crate) struct FramedRead2<T> {
|
||||
inner: T,
|
||||
eof: bool,
|
||||
is_readable: bool,
|
||||
@@ -136,7 +136,7 @@ where
|
||||
|
||||
// ===== impl FramedRead2 =====
|
||||
|
||||
pub fn framed_read2<T>(inner: T) -> FramedRead2<T> {
|
||||
pub(crate) fn framed_read2<T>(inner: T) -> FramedRead2<T> {
|
||||
FramedRead2 {
|
||||
inner,
|
||||
eof: false,
|
||||
@@ -145,7 +145,7 @@ pub fn framed_read2<T>(inner: T) -> FramedRead2<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn framed_read2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedRead2<T> {
|
||||
pub(crate) fn framed_read2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedRead2<T> {
|
||||
if buf.capacity() < INITIAL_CAPACITY {
|
||||
let bytes_to_reserve = INITIAL_CAPACITY - buf.capacity();
|
||||
buf.reserve(bytes_to_reserve);
|
||||
@@ -159,19 +159,19 @@ pub fn framed_read2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedRead2<T
|
||||
}
|
||||
|
||||
impl<T> FramedRead2<T> {
|
||||
pub fn get_ref(&self) -> &T {
|
||||
pub(crate) fn get_ref(&self) -> &T {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> T {
|
||||
pub(crate) fn into_inner(self) -> T {
|
||||
self.inner
|
||||
}
|
||||
|
||||
pub fn into_parts(self) -> (T, BytesMut) {
|
||||
pub(crate) fn into_parts(self) -> (T, BytesMut) {
|
||||
(self.inner, self.buffer)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
pub(crate) fn get_mut(&mut self) -> &mut T {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ pub struct FramedWrite<T, E> {
|
||||
inner: FramedWrite2<Fuse<T, E>>,
|
||||
}
|
||||
|
||||
pub struct FramedWrite2<T> {
|
||||
pub(crate) struct FramedWrite2<T> {
|
||||
inner: T,
|
||||
buffer: BytesMut,
|
||||
}
|
||||
@@ -136,14 +136,14 @@ where
|
||||
|
||||
// ===== impl FramedWrite2 =====
|
||||
|
||||
pub fn framed_write2<T>(inner: T) -> FramedWrite2<T> {
|
||||
pub(crate) fn framed_write2<T>(inner: T) -> FramedWrite2<T> {
|
||||
FramedWrite2 {
|
||||
inner,
|
||||
buffer: BytesMut::with_capacity(INITIAL_CAPACITY),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn framed_write2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedWrite2<T> {
|
||||
pub(crate) fn framed_write2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedWrite2<T> {
|
||||
if buf.capacity() < INITIAL_CAPACITY {
|
||||
let bytes_to_reserve = INITIAL_CAPACITY - buf.capacity();
|
||||
buf.reserve(bytes_to_reserve);
|
||||
@@ -152,19 +152,19 @@ pub fn framed_write2_with_buffer<T>(inner: T, mut buf: BytesMut) -> FramedWrite2
|
||||
}
|
||||
|
||||
impl<T> FramedWrite2<T> {
|
||||
pub fn get_ref(&self) -> &T {
|
||||
pub(crate) fn get_ref(&self) -> &T {
|
||||
&self.inner
|
||||
}
|
||||
|
||||
pub fn into_inner(self) -> T {
|
||||
pub(crate) fn into_inner(self) -> T {
|
||||
self.inner
|
||||
}
|
||||
|
||||
pub fn into_parts(self) -> (T, BytesMut) {
|
||||
pub(crate) fn into_parts(self) -> (T, BytesMut) {
|
||||
(self.inner, self.buffer)
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
pub(crate) fn get_mut(&mut self) -> &mut T {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-codec/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! Utilities for encoding and decoding frames.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-current-thread/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! A single-threaded executor which executes tasks on the same thread from which
|
||||
|
||||
@@ -16,7 +16,7 @@ use tokio_executor::park::Unpark;
|
||||
/// A generic task-aware scheduler.
|
||||
///
|
||||
/// This is used both by `FuturesUnordered` and the current-thread executor.
|
||||
pub struct Scheduler<U> {
|
||||
pub(crate) struct Scheduler<U> {
|
||||
inner: Arc<Inner<U>>,
|
||||
nodes: List<U>,
|
||||
}
|
||||
@@ -117,7 +117,7 @@ enum Dequeue<U> {
|
||||
struct Task(Pin<Box<dyn Future<Output = ()>>>);
|
||||
|
||||
/// A task that is scheduled. `turn` must be called
|
||||
pub struct Scheduled<'a, U> {
|
||||
pub(crate) struct Scheduled<'a, U> {
|
||||
task: &'a mut Task,
|
||||
node: &'a Arc<Node<U>>,
|
||||
done: &'a mut bool,
|
||||
@@ -131,7 +131,7 @@ where
|
||||
///
|
||||
/// The returned `Scheduler` does not contain any items and, in this
|
||||
/// state, `Scheduler::poll` will return `Ok(Async::Ready(None))`.
|
||||
pub fn new(unpark: U) -> Self {
|
||||
pub(crate) fn new(unpark: U) -> Self {
|
||||
let stub = Arc::new(Node {
|
||||
item: UnsafeCell::new(None),
|
||||
notified_at: AtomicUsize::new(0),
|
||||
@@ -156,11 +156,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn waker(&self) -> Waker {
|
||||
pub(crate) fn waker(&self) -> Waker {
|
||||
waker_inner(self.inner.clone())
|
||||
}
|
||||
|
||||
pub fn schedule(&mut self, item: Pin<Box<dyn Future<Output = ()>>>) {
|
||||
pub(crate) fn schedule(&mut self, item: Pin<Box<dyn Future<Output = ()>>>) {
|
||||
// Get the current scheduler tick
|
||||
let tick_num = self.inner.tick_num.load(SeqCst);
|
||||
|
||||
@@ -187,7 +187,7 @@ where
|
||||
}
|
||||
|
||||
/// Returns `true` if there are currently any pending futures
|
||||
pub fn has_pending_futures(&mut self) -> bool {
|
||||
pub(crate) fn has_pending_futures(&mut self) -> bool {
|
||||
// See function definition for why the unsafe is needed and
|
||||
// correctly used here
|
||||
unsafe { self.inner.has_pending_futures() }
|
||||
@@ -198,7 +198,7 @@ where
|
||||
///
|
||||
/// This function should be called whenever the caller is notified via a
|
||||
/// wakeup.
|
||||
pub fn tick(&mut self, eid: u64, num_futures: &AtomicUsize) -> bool {
|
||||
pub(crate) fn tick(&mut self, eid: u64, num_futures: &AtomicUsize) -> bool {
|
||||
let mut ret = false;
|
||||
let tick = self.inner.tick_num.fetch_add(1, SeqCst).wrapping_add(1);
|
||||
|
||||
@@ -331,7 +331,7 @@ where
|
||||
|
||||
impl<U: Unpark> Scheduled<'_, U> {
|
||||
/// Polls the task, returns `true` if the task has completed.
|
||||
pub fn tick(&mut self) -> bool {
|
||||
pub(crate) fn tick(&mut self) -> bool {
|
||||
let waker = unsafe {
|
||||
// Safety: we don't hold this waker ref longer than
|
||||
// this `tick` function
|
||||
@@ -349,7 +349,7 @@ impl<U: Unpark> Scheduled<'_, U> {
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub fn new(future: Pin<Box<dyn Future<Output = ()> + 'static>>) -> Self {
|
||||
pub(crate) fn new(future: Pin<Box<dyn Future<Output = ()> + 'static>>) -> Self {
|
||||
Task(future)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-executor/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! Task execution related traits and utilities.
|
||||
|
||||
@@ -194,7 +194,7 @@ thread_local! {
|
||||
// ==== impl Parker ====
|
||||
|
||||
impl Parker {
|
||||
pub fn new() -> Self {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
unparker: Arc::new(Inner {
|
||||
state: AtomicUsize::new(IDLE),
|
||||
@@ -204,15 +204,15 @@ impl Parker {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unparker(&self) -> &Arc<Inner> {
|
||||
pub(crate) fn unparker(&self) -> &Arc<Inner> {
|
||||
&self.unparker
|
||||
}
|
||||
|
||||
pub fn park(&self) -> Result<(), ParkError> {
|
||||
pub(crate) fn park(&self) -> Result<(), ParkError> {
|
||||
self.unparker.park(None)
|
||||
}
|
||||
|
||||
pub fn park_timeout(&self, timeout: Duration) -> Result<(), ParkError> {
|
||||
pub(crate) fn park_timeout(&self, timeout: Duration) -> Result<(), ParkError> {
|
||||
self.unparker.park(Some(timeout))
|
||||
}
|
||||
}
|
||||
@@ -221,16 +221,16 @@ impl Parker {
|
||||
|
||||
impl Inner {
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
pub fn into_raw(this: Arc<Inner>) -> *const () {
|
||||
pub(crate) fn into_raw(this: Arc<Inner>) -> *const () {
|
||||
Arc::into_raw(this) as *const ()
|
||||
}
|
||||
|
||||
pub unsafe fn from_raw(ptr: *const ()) -> Arc<Inner> {
|
||||
pub(crate) unsafe fn from_raw(ptr: *const ()) -> Arc<Inner> {
|
||||
Arc::from_raw(ptr as *const Inner)
|
||||
}
|
||||
|
||||
/// Park the current thread for at most `dur`.
|
||||
pub fn park(&self, timeout: Option<Duration>) -> Result<(), ParkError> {
|
||||
pub(crate) fn park(&self, timeout: Option<Duration>) -> Result<(), ParkError> {
|
||||
// If currently notified, then we skip sleeping. This is checked outside
|
||||
// of the lock to avoid acquiring a mutex if not necessary.
|
||||
match self.state.compare_and_swap(NOTIFY, IDLE, Ordering::SeqCst) {
|
||||
@@ -272,7 +272,7 @@ impl Inner {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn unpark(&self) {
|
||||
pub(crate) fn unpark(&self) {
|
||||
// First, try transitioning from IDLE -> NOTIFY, this does not require a
|
||||
// lock.
|
||||
match self.state.compare_and_swap(IDLE, NOTIFY, Ordering::SeqCst) {
|
||||
|
||||
+6
-1
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-fs/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
|
||||
@@ -52,6 +52,9 @@ mod shutdown;
|
||||
mod write;
|
||||
mod write_all;
|
||||
|
||||
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
|
||||
pub use self::async_buf_read_ext::AsyncBufReadExt;
|
||||
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
|
||||
pub use self::async_read_ext::AsyncReadExt;
|
||||
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
|
||||
pub use self::async_write_ext::AsyncWriteExt;
|
||||
|
||||
+6
-1
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-io/0.2.0-alpha.1")]
|
||||
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! Core I/O traits and combinators when working with Tokio.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-macros/0.2.0-alpha.1")]
|
||||
#![warn(missing_debug_implementations, unreachable_pub, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! Macros for use with Tokio
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-process/0.3.0-alpha.1")]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
//! An implementation of asynchronous process management for Tokio.
|
||||
//!
|
||||
@@ -117,11 +125,6 @@
|
||||
//! `tokio_process::Child` is dropped. The behavior of the standard library can
|
||||
//! be regained with the `Child::forget` method.
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-process/0.3.0")]
|
||||
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
#[cfg(unix)]
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
@@ -81,7 +81,7 @@ impl OrphanQueue<process::Child> for GlobalOrphanQueue {
|
||||
}
|
||||
|
||||
#[must_use = "futures do nothing unless polled"]
|
||||
pub struct Child {
|
||||
pub(crate) struct Child {
|
||||
inner: Reaper<process::Child, GlobalOrphanQueue, Signal>,
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ pub(crate) fn spawn_child(cmd: &mut process::Command, handle: &Handle) -> io::Re
|
||||
}
|
||||
|
||||
impl Child {
|
||||
pub fn id(&self) -> u32 {
|
||||
pub(crate) fn id(&self) -> u32 {
|
||||
self.inner.id()
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ impl Future for Child {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Fd<T> {
|
||||
pub(crate) struct Fd<T> {
|
||||
inner: T,
|
||||
}
|
||||
|
||||
@@ -196,9 +196,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub type ChildStdin = PollEvented<Fd<process::ChildStdin>>;
|
||||
pub type ChildStdout = PollEvented<Fd<process::ChildStdout>>;
|
||||
pub type ChildStderr = PollEvented<Fd<process::ChildStderr>>;
|
||||
pub(crate) type ChildStdin = PollEvented<Fd<process::ChildStdin>>;
|
||||
pub(crate) type ChildStdout = PollEvented<Fd<process::ChildStdout>>;
|
||||
pub(crate) type ChildStderr = PollEvented<Fd<process::ChildStderr>>;
|
||||
|
||||
fn stdio<T>(option: Option<T>, handle: &Handle) -> io::Result<Option<PollEvented<Fd<T>>>>
|
||||
where
|
||||
|
||||
@@ -45,7 +45,7 @@ use winapi::um::winbase::*;
|
||||
use winapi::um::winnt::*;
|
||||
|
||||
#[must_use = "futures do nothing unless polled"]
|
||||
pub struct Child {
|
||||
pub(crate) struct Child {
|
||||
child: process::Child,
|
||||
waiting: Option<Waiting>,
|
||||
}
|
||||
@@ -87,7 +87,7 @@ pub(crate) fn spawn_child(cmd: &mut process::Command, handle: &Handle) -> io::Re
|
||||
}
|
||||
|
||||
impl Child {
|
||||
pub fn id(&self) -> u32 {
|
||||
pub(crate) fn id(&self) -> u32 {
|
||||
self.child.id()
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,7 @@ unsafe extern "system" fn callback(ptr: PVOID, _timer_fired: BOOLEAN) {
|
||||
let _ = complete.take().unwrap().send(());
|
||||
}
|
||||
|
||||
pub fn try_wait(child: &process::Child) -> io::Result<Option<ExitStatus>> {
|
||||
pub(crate) fn try_wait(child: &process::Child) -> io::Result<Option<ExitStatus>> {
|
||||
unsafe {
|
||||
match WaitForSingleObject(child.as_raw_handle(), 0) {
|
||||
WAIT_OBJECT_0 => {}
|
||||
@@ -178,9 +178,9 @@ pub fn try_wait(child: &process::Child) -> io::Result<Option<ExitStatus>> {
|
||||
}
|
||||
}
|
||||
|
||||
pub type ChildStdin = PollEvented<NamedPipe>;
|
||||
pub type ChildStdout = PollEvented<NamedPipe>;
|
||||
pub type ChildStderr = PollEvented<NamedPipe>;
|
||||
pub(crate) type ChildStdin = PollEvented<NamedPipe>;
|
||||
pub(crate) type ChildStdout = PollEvented<NamedPipe>;
|
||||
pub(crate) type ChildStderr = PollEvented<NamedPipe>;
|
||||
|
||||
fn stdio<T>(option: Option<T>, handle: &Handle) -> io::Result<Option<PollEvented<NamedPipe>>>
|
||||
where
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-reactor/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! Event loop that drives Tokio I/O resources.
|
||||
@@ -585,11 +590,11 @@ mod platform {
|
||||
use mio::unix::UnixReady;
|
||||
use mio::Ready;
|
||||
|
||||
pub fn hup() -> Ready {
|
||||
pub(crate) fn hup() -> Ready {
|
||||
UnixReady::hup().into()
|
||||
}
|
||||
|
||||
pub fn is_hup(ready: Ready) -> bool {
|
||||
pub(crate) fn is_hup(ready: Ready) -> bool {
|
||||
UnixReady::from(ready).is_hup()
|
||||
}
|
||||
}
|
||||
@@ -598,11 +603,11 @@ mod platform {
|
||||
mod platform {
|
||||
use mio::Ready;
|
||||
|
||||
pub fn hup() -> Ready {
|
||||
pub(crate) fn hup() -> Ready {
|
||||
Ready::empty()
|
||||
}
|
||||
|
||||
pub fn is_hup(_: Ready) -> bool {
|
||||
pub(crate) fn is_hup(_: Ready) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ use std::thread::{self, ThreadId};
|
||||
/// Read operations lock only one shard specific to the current thread, while write operations lock
|
||||
/// every shard in succession. This strategy makes concurrent read operations faster due to less
|
||||
/// contention, but write operations are slower due to increased amount of locking.
|
||||
pub struct RwLock<T> {
|
||||
pub(crate) struct RwLock<T> {
|
||||
/// A list of locks protecting the internal data.
|
||||
shards: Vec<CachePadded<parking_lot::RwLock<()>>>,
|
||||
|
||||
@@ -43,7 +43,7 @@ unsafe impl<T: Send + Sync> Sync for RwLock<T> {}
|
||||
|
||||
impl<T> RwLock<T> {
|
||||
/// Creates a new `RwLock` initialized with `value`.
|
||||
pub fn new(value: T) -> RwLock<T> {
|
||||
pub(crate) fn new(value: T) -> RwLock<T> {
|
||||
// The number of shards is a power of two so that the modulo operation in `read` becomes a
|
||||
// simple bitwise "and".
|
||||
let num_shards = num_cpus::get().next_power_of_two();
|
||||
@@ -65,7 +65,7 @@ impl<T> RwLock<T> {
|
||||
/// or writers will acquire the lock first.
|
||||
///
|
||||
/// Returns an RAII guard which will release this thread's shared access once it is dropped.
|
||||
pub fn read(&self) -> RwLockReadGuard<'_, T> {
|
||||
pub(crate) fn read(&self) -> RwLockReadGuard<'_, T> {
|
||||
// Take the current thread index and map it to a shard index. Thread indices will tend to
|
||||
// distribute shards among threads equally, thus reducing contention due to read-locking.
|
||||
let shard_index = thread_index() & (self.shards.len() - 1);
|
||||
@@ -84,7 +84,7 @@ impl<T> RwLock<T> {
|
||||
/// the lock.
|
||||
///
|
||||
/// Returns an RAII guard which will drop the write access of this rwlock when dropped.
|
||||
pub fn write(&self) -> RwLockWriteGuard<'_, T> {
|
||||
pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> {
|
||||
// Write-lock each shard in succession.
|
||||
for shard in &self.shards {
|
||||
// The write guard is forgotten, but the lock will be manually unlocked in `drop`.
|
||||
@@ -99,7 +99,7 @@ impl<T> RwLock<T> {
|
||||
}
|
||||
|
||||
/// A guard used to release the shared read access of a `RwLock` when dropped.
|
||||
pub struct RwLockReadGuard<'a, T> {
|
||||
pub(crate) struct RwLockReadGuard<'a, T> {
|
||||
parent: &'a RwLock<T>,
|
||||
_guard: parking_lot::RwLockReadGuard<'a, ()>,
|
||||
_marker: PhantomData<parking_lot::RwLockReadGuard<'a, T>>,
|
||||
@@ -116,7 +116,7 @@ impl<'a, T> Deref for RwLockReadGuard<'a, T> {
|
||||
}
|
||||
|
||||
/// A guard used to release the exclusive write access of a `RwLock` when dropped.
|
||||
pub struct RwLockWriteGuard<'a, T> {
|
||||
pub(crate) struct RwLockWriteGuard<'a, T> {
|
||||
parent: &'a RwLock<T>,
|
||||
_marker: PhantomData<parking_lot::RwLockWriteGuard<'a, T>>,
|
||||
}
|
||||
@@ -154,7 +154,7 @@ impl<'a, T> DerefMut for RwLockWriteGuard<'a, T> {
|
||||
/// between 0 and the number of running threads, but there are no guarantees. During TLS teardown
|
||||
/// the associated index might change.
|
||||
#[inline]
|
||||
pub fn thread_index() -> usize {
|
||||
pub(crate) fn thread_index() -> usize {
|
||||
REGISTRATION.try_with(|reg| reg.index).unwrap_or(0)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-signal/0.3.0-alpha.1")]
|
||||
#![warn(missing_debug_implementations, missing_docs, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![cfg_attr(test, feature(async_await))]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
unreachable_pub,
|
||||
rust_2018_idioms
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-tcp/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-test/0.2.0-alpha.1")]
|
||||
#![warn(
|
||||
missing_docs,
|
||||
missing_debug_implementations,
|
||||
unreachable_pub,
|
||||
rust_2018_idioms
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
|
||||
@@ -8,14 +8,14 @@ pub(crate) struct Callback {
|
||||
}
|
||||
|
||||
impl Callback {
|
||||
pub fn new<F>(f: F) -> Self
|
||||
pub(crate) fn new<F>(f: F) -> Self
|
||||
where
|
||||
F: Fn(&Worker) + Send + Sync + 'static,
|
||||
{
|
||||
Callback { f: Arc::new(f) }
|
||||
}
|
||||
|
||||
pub fn call(&self, worker: &Worker) {
|
||||
pub(crate) fn call(&self, worker: &Worker) {
|
||||
(self.f)(worker)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ use std::time::Duration;
|
||||
/// Thread pool specific configuration values
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct Config {
|
||||
pub keep_alive: Option<Duration>,
|
||||
pub(crate) keep_alive: Option<Duration>,
|
||||
// Used to configure a worker thread
|
||||
pub name_prefix: Option<String>,
|
||||
pub stack_size: Option<usize>,
|
||||
pub around_worker: Option<Callback>,
|
||||
pub after_start: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub before_stop: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub panic_handler: Option<PanicHandler>,
|
||||
pub(crate) name_prefix: Option<String>,
|
||||
pub(crate) stack_size: Option<usize>,
|
||||
pub(crate) around_worker: Option<Callback>,
|
||||
pub(crate) after_start: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub(crate) before_stop: Option<Arc<dyn Fn() + Send + Sync>>,
|
||||
pub(crate) panic_handler: Option<PanicHandler>,
|
||||
}
|
||||
|
||||
// Define type alias to avoid clippy::type_complexity.
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-threadpool/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
|
||||
//! A work-stealing based thread pool for executing futures.
|
||||
|
||||
@@ -9,7 +9,7 @@ pub(crate) type BoxUnpark = Box<dyn Unpark>;
|
||||
pub(crate) struct BoxedPark<T>(T);
|
||||
|
||||
impl<T> BoxedPark<T> {
|
||||
pub fn new(inner: T) -> Self {
|
||||
pub(crate) fn new(inner: T) -> Self {
|
||||
BoxedPark(inner)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,18 +67,18 @@ struct State(usize);
|
||||
/// This flag also serves as a "notification" bit. If another thread is
|
||||
/// attempting to hand off a worker to the backup thread, then the pushed bit
|
||||
/// will not be set when the thread tries to shutdown.
|
||||
pub const PUSHED: usize = 0b001;
|
||||
pub(crate) const PUSHED: usize = 0b001;
|
||||
|
||||
/// Set when the thread is running
|
||||
pub const RUNNING: usize = 0b010;
|
||||
pub(crate) const RUNNING: usize = 0b010;
|
||||
|
||||
/// Set when the thread pool has terminated
|
||||
pub const TERMINATED: usize = 0b100;
|
||||
pub(crate) const TERMINATED: usize = 0b100;
|
||||
|
||||
// ===== impl Backup =====
|
||||
|
||||
impl Backup {
|
||||
pub fn new() -> Backup {
|
||||
pub(crate) fn new() -> Backup {
|
||||
Backup {
|
||||
handoff: UnsafeCell::new(None),
|
||||
state: AtomicUsize::new(State::new().into()),
|
||||
@@ -88,7 +88,7 @@ impl Backup {
|
||||
}
|
||||
|
||||
/// Called when the thread is starting
|
||||
pub fn start(&self, worker_id: &WorkerId) {
|
||||
pub(crate) fn start(&self, worker_id: &WorkerId) {
|
||||
debug_assert!({
|
||||
let state: State = self.state.load(Relaxed).into();
|
||||
|
||||
@@ -107,7 +107,7 @@ impl Backup {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_running(&self) -> bool {
|
||||
pub(crate) fn is_running(&self) -> bool {
|
||||
let state: State = self.state.load(Relaxed).into();
|
||||
state.is_running()
|
||||
}
|
||||
@@ -115,7 +115,7 @@ impl Backup {
|
||||
/// Hands off the worker to a thread.
|
||||
///
|
||||
/// Returns `true` if the thread needs to be spawned.
|
||||
pub fn worker_handoff(&self, worker_id: WorkerId) -> bool {
|
||||
pub(crate) fn worker_handoff(&self, worker_id: WorkerId) -> bool {
|
||||
unsafe {
|
||||
// The backup worker should not already have been handoff a worker.
|
||||
debug_assert!((*self.handoff.get()).is_none());
|
||||
@@ -139,7 +139,7 @@ impl Backup {
|
||||
}
|
||||
|
||||
/// Terminate the worker
|
||||
pub fn signal_stop(&self) {
|
||||
pub(crate) fn signal_stop(&self) {
|
||||
let prev: State = self.state.fetch_xor(TERMINATED | PUSHED, AcqRel).into();
|
||||
|
||||
debug_assert!(!prev.is_terminated());
|
||||
@@ -151,14 +151,14 @@ impl Backup {
|
||||
}
|
||||
|
||||
/// Release the worker
|
||||
pub fn release(&self) {
|
||||
pub(crate) fn release(&self) {
|
||||
let prev: State = self.state.fetch_xor(RUNNING, AcqRel).into();
|
||||
|
||||
debug_assert!(prev.is_running());
|
||||
}
|
||||
|
||||
/// Wait for a worker handoff
|
||||
pub fn wait_for_handoff(&self, timeout: Option<Duration>) -> Handoff {
|
||||
pub(crate) fn wait_for_handoff(&self, timeout: Option<Duration>) -> Handoff {
|
||||
let sleep_until = timeout.map(|dur| Instant::now() + dur);
|
||||
let mut state: State = self.state.load(Acquire).into();
|
||||
|
||||
@@ -208,23 +208,23 @@ impl Backup {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_pushed(&self) -> bool {
|
||||
pub(crate) fn is_pushed(&self) -> bool {
|
||||
let state: State = self.state.load(Relaxed).into();
|
||||
state.is_pushed()
|
||||
}
|
||||
|
||||
pub fn set_pushed(&self, ordering: Ordering) {
|
||||
pub(crate) fn set_pushed(&self, ordering: Ordering) {
|
||||
let prev: State = self.state.fetch_or(PUSHED, ordering).into();
|
||||
debug_assert!(!prev.is_pushed());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn next_sleeper(&self) -> BackupId {
|
||||
pub(crate) fn next_sleeper(&self) -> BackupId {
|
||||
unsafe { *self.next_sleeper.get() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_next_sleeper(&self, val: BackupId) {
|
||||
pub(crate) fn set_next_sleeper(&self, val: BackupId) {
|
||||
unsafe {
|
||||
*self.next_sleeper.get() = val;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const ABA_GUARD_MASK: usize = (1 << (32 - ABA_GUARD_SHIFT)) - 1;
|
||||
// ===== impl BackupStack =====
|
||||
|
||||
impl BackupStack {
|
||||
pub fn new() -> BackupStack {
|
||||
pub(crate) fn new() -> BackupStack {
|
||||
let state = AtomicUsize::new(State::new().into());
|
||||
BackupStack { state }
|
||||
}
|
||||
@@ -47,7 +47,7 @@ impl BackupStack {
|
||||
///
|
||||
/// Returns `Err` if the pool has transitioned to the `TERMINATED` state.
|
||||
/// When terminated, pushing new entries is no longer permitted.
|
||||
pub fn push(&self, entries: &[Backup], id: BackupId) -> Result<(), ()> {
|
||||
pub(crate) fn push(&self, entries: &[Backup], id: BackupId) -> Result<(), ()> {
|
||||
let mut state: State = self.state.load(Acquire).into();
|
||||
|
||||
entries[id.0].set_pushed(AcqRel);
|
||||
@@ -91,7 +91,7 @@ impl BackupStack {
|
||||
///
|
||||
/// * `Ok(None)` if the stack is empty.
|
||||
/// * `Err(_)` is returned if the pool has been shutdown.
|
||||
pub fn pop(&self, entries: &[Backup], terminate: bool) -> Result<Option<BackupId>, ()> {
|
||||
pub(crate) fn pop(&self, entries: &[Backup], terminate: bool) -> Result<Option<BackupId>, ()> {
|
||||
// Figure out the empty value
|
||||
let terminal = if terminate { TERMINATED } else { EMPTY };
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ pub(crate) struct Pool {
|
||||
//
|
||||
// The value of this atomic is deserialized into a `pool::State` instance.
|
||||
// See comments for that type.
|
||||
pub state: CachePadded<AtomicUsize>,
|
||||
pub(crate) state: CachePadded<AtomicUsize>,
|
||||
|
||||
// Stack tracking sleeping workers.
|
||||
sleep_stack: CachePadded<worker::Stack>,
|
||||
@@ -49,19 +49,19 @@ pub(crate) struct Pool {
|
||||
// futures.
|
||||
//
|
||||
// The number of workers will *usually* be small.
|
||||
pub workers: Arc<[worker::Entry]>,
|
||||
pub(crate) workers: Arc<[worker::Entry]>,
|
||||
|
||||
// The global MPMC queue of tasks.
|
||||
//
|
||||
// Spawned tasks are pushed into this queue. Although worker threads have their own dedicated
|
||||
// task queues, they periodically steal tasks from this global queue, too.
|
||||
pub queue: Arc<Injector<Arc<Task>>>,
|
||||
pub(crate) queue: Arc<Injector<Arc<Task>>>,
|
||||
|
||||
// Completes the shutdown process when the `ThreadPool` and all `Worker`s get dropped.
|
||||
//
|
||||
// When spawning a new `Worker`, this weak reference is upgraded and handed out to the new
|
||||
// thread.
|
||||
pub trigger: Weak<ShutdownTrigger>,
|
||||
pub(crate) trigger: Weak<ShutdownTrigger>,
|
||||
|
||||
// Backup thread state
|
||||
//
|
||||
@@ -71,19 +71,19 @@ pub(crate) struct Pool {
|
||||
backup: Box<[Backup]>,
|
||||
|
||||
// Stack of sleeping backup threads
|
||||
pub backup_stack: BackupStack,
|
||||
pub(crate) backup_stack: BackupStack,
|
||||
|
||||
// State regarding coordinating blocking sections and tracking tasks that
|
||||
// are pending blocking capacity.
|
||||
blocking: Blocking,
|
||||
|
||||
// Configuration
|
||||
pub config: Config,
|
||||
pub(crate) config: Config,
|
||||
}
|
||||
|
||||
impl Pool {
|
||||
/// Create a new `Pool`
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
workers: Arc<[worker::Entry]>,
|
||||
trigger: Weak<ShutdownTrigger>,
|
||||
max_blocking: usize,
|
||||
@@ -133,7 +133,7 @@ impl Pool {
|
||||
|
||||
/// Start shutting down the pool. This means that no new futures will be
|
||||
/// accepted.
|
||||
pub fn shutdown(&self, now: bool, purge_queue: bool) {
|
||||
pub(crate) fn shutdown(&self, now: bool, purge_queue: bool) {
|
||||
let mut state: State = self.state.load(Acquire).into();
|
||||
|
||||
trace!("shutdown; state={:?}", state);
|
||||
@@ -198,11 +198,11 @@ impl Pool {
|
||||
/// Called by `Worker` as it tries to enter a sleeping state. Before it
|
||||
/// sleeps, it must push itself onto the sleep stack. This enables other
|
||||
/// threads to see it when signaling work.
|
||||
pub fn push_sleeper(&self, idx: usize) -> Result<(), ()> {
|
||||
pub(crate) fn push_sleeper(&self, idx: usize) -> Result<(), ()> {
|
||||
self.sleep_stack.push(&self.workers, idx)
|
||||
}
|
||||
|
||||
pub fn terminate_sleeping_workers(&self) {
|
||||
pub(crate) fn terminate_sleeping_workers(&self) {
|
||||
use crate::worker::Lifecycle::Signaled;
|
||||
|
||||
trace!(" -> shutting down workers");
|
||||
@@ -222,7 +222,7 @@ impl Pool {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn poll_blocking_capacity(
|
||||
pub(crate) fn poll_blocking_capacity(
|
||||
&self,
|
||||
task: &Arc<Task>,
|
||||
) -> Poll<Result<(), crate::BlockingError>> {
|
||||
@@ -233,7 +233,7 @@ impl Pool {
|
||||
///
|
||||
/// Called from either inside or outside of the scheduler. If currently on
|
||||
/// the scheduler, then a fast path is taken.
|
||||
pub fn submit(&self, task: Arc<Task>, pool: &Arc<Pool>) {
|
||||
pub(crate) fn submit(&self, task: Arc<Task>, pool: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **pool);
|
||||
|
||||
Worker::with_current(|worker| {
|
||||
@@ -265,7 +265,7 @@ impl Pool {
|
||||
///
|
||||
/// Called from outside of the scheduler, this function is how new tasks
|
||||
/// enter the system.
|
||||
pub fn submit_external(&self, task: Arc<Task>, pool: &Arc<Pool>) {
|
||||
pub(crate) fn submit_external(&self, task: Arc<Task>, pool: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **pool);
|
||||
|
||||
trace!(" -> submit external");
|
||||
@@ -274,7 +274,7 @@ impl Pool {
|
||||
self.signal_work(pool);
|
||||
}
|
||||
|
||||
pub fn release_backup(&self, backup_id: BackupId) -> Result<(), ()> {
|
||||
pub(crate) fn release_backup(&self, backup_id: BackupId) -> Result<(), ()> {
|
||||
// First update the state, this cannot fail because the caller must have
|
||||
// exclusive access to the backup token.
|
||||
self.backup[backup_id.0].release();
|
||||
@@ -283,13 +283,13 @@ impl Pool {
|
||||
self.backup_stack.push(&self.backup, backup_id)
|
||||
}
|
||||
|
||||
pub fn notify_blocking_task(&self, pool: &Arc<Pool>) {
|
||||
pub(crate) fn notify_blocking_task(&self, pool: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **pool);
|
||||
self.blocking.notify_task(&pool);
|
||||
}
|
||||
|
||||
/// Provision a thread to run a worker
|
||||
pub fn spawn_thread(&self, id: WorkerId, pool: &Arc<Pool>) {
|
||||
pub(crate) fn spawn_thread(&self, id: WorkerId, pool: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **pool);
|
||||
|
||||
let backup_id = match self.backup_stack.pop(&self.backup, false) {
|
||||
@@ -396,7 +396,7 @@ impl Pool {
|
||||
|
||||
/// If there are any other workers currently relaxing, signal them that work
|
||||
/// is available so that they can try to find more work to process.
|
||||
pub fn signal_work(&self, pool: &Arc<Pool>) {
|
||||
pub(crate) fn signal_work(&self, pool: &Arc<Pool>) {
|
||||
debug_assert_eq!(*self, **pool);
|
||||
|
||||
use crate::worker::Lifecycle::Signaled;
|
||||
@@ -422,7 +422,7 @@ impl Pool {
|
||||
/// Generates a random number
|
||||
///
|
||||
/// Uses a thread-local random number generator based on XorShift.
|
||||
pub fn rand_usize(&self) -> usize {
|
||||
pub(crate) fn rand_usize(&self) -> usize {
|
||||
thread_local! {
|
||||
static RNG: Cell<Wrapping<u32>> = Cell::new(Wrapping(prng_seed()));
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ const NUM_SHIFT: usize = 1;
|
||||
//
|
||||
impl Blocking {
|
||||
/// Create a new `Blocking`.
|
||||
pub fn new(capacity: usize) -> Blocking {
|
||||
pub(crate) fn new(capacity: usize) -> Blocking {
|
||||
assert!(capacity > 0, "blocking capacity must be greater than zero");
|
||||
|
||||
let stub = Box::new(Task::stub());
|
||||
@@ -110,7 +110,7 @@ impl Blocking {
|
||||
///
|
||||
/// The caller must ensure that `task` has not previously been queued to be
|
||||
/// notified when capacity becomes available.
|
||||
pub fn poll_blocking_capacity(
|
||||
pub(crate) fn poll_blocking_capacity(
|
||||
&self,
|
||||
task: &Arc<Task>,
|
||||
) -> Poll<Result<(), crate::BlockingError>> {
|
||||
@@ -243,7 +243,7 @@ impl Blocking {
|
||||
(*prev).next_blocking.store(task, Release);
|
||||
}
|
||||
|
||||
pub fn notify_task(&self, pool: &Arc<Pool>) {
|
||||
pub(crate) fn notify_task(&self, pool: &Arc<Pool>) {
|
||||
let prev = self.lock.fetch_add(1, AcqRel);
|
||||
|
||||
if prev != 0 {
|
||||
|
||||
@@ -40,13 +40,13 @@ pub(crate) struct Task {
|
||||
///
|
||||
/// The worker ID is represented by a `u32` rather than `usize` in order to save some space
|
||||
/// on 64-bit platforms.
|
||||
pub reg_worker: Cell<Option<u32>>,
|
||||
pub(crate) reg_worker: Cell<Option<u32>>,
|
||||
|
||||
/// The key associated with this task in the `Slab` it was registered in.
|
||||
///
|
||||
/// This field can be a `Cell` because it's only accessed by the worker thread that has
|
||||
/// registered the task.
|
||||
pub reg_index: Cell<usize>,
|
||||
pub(crate) reg_index: Cell<usize>,
|
||||
|
||||
/// Store the future at the head of the struct
|
||||
///
|
||||
@@ -67,7 +67,7 @@ type BoxFuture = Pin<Box<dyn Future<Output = ()> + Send + 'static>>;
|
||||
|
||||
impl Task {
|
||||
/// Create a new `Task` as a harness for `future`.
|
||||
pub fn new(future: BoxFuture) -> Task {
|
||||
pub(crate) fn new(future: BoxFuture) -> Task {
|
||||
Task {
|
||||
state: AtomicUsize::new(State::new().into()),
|
||||
blocking: AtomicUsize::new(BlockingState::new().into()),
|
||||
@@ -95,7 +95,7 @@ impl Task {
|
||||
|
||||
/// Execute the task returning `Run::Schedule` if the task needs to be
|
||||
/// scheduled again.
|
||||
pub fn run(me: &Arc<Task>, pool: &Arc<Pool>) -> Run {
|
||||
pub(crate) fn run(me: &Arc<Task>, pool: &Arc<Pool>) -> Run {
|
||||
use self::State::*;
|
||||
|
||||
// Transition task to running state. At this point, the task must be
|
||||
@@ -200,7 +200,7 @@ impl Task {
|
||||
///
|
||||
/// This is called when the threadpool shuts down and the task has already beed polled but not
|
||||
/// completed.
|
||||
pub fn abort(&self) {
|
||||
pub(crate) fn abort(&self) {
|
||||
use self::State::*;
|
||||
|
||||
let mut state = self.state.load(Acquire).into();
|
||||
@@ -232,12 +232,12 @@ impl Task {
|
||||
}
|
||||
|
||||
/// Notify the task it has been allocated blocking capacity
|
||||
pub fn notify_blocking(me: Arc<Task>, pool: &Arc<Pool>) {
|
||||
pub(crate) fn notify_blocking(me: Arc<Task>, pool: &Arc<Pool>) {
|
||||
BlockingState::notify_blocking(&me.blocking, AcqRel);
|
||||
Task::schedule(&me, pool);
|
||||
}
|
||||
|
||||
pub fn schedule(me: &Arc<Self>, pool: &Arc<Pool>) {
|
||||
pub(crate) fn schedule(me: &Arc<Self>, pool: &Arc<Pool>) {
|
||||
if me.schedule2() {
|
||||
let task = me.clone();
|
||||
pool.submit(task, &pool);
|
||||
@@ -281,7 +281,7 @@ impl Task {
|
||||
/// Consumes any allocated capacity to block.
|
||||
///
|
||||
/// Returns `true` if capacity was allocated, `false` otherwise.
|
||||
pub fn consume_blocking_allocation(&self) -> CanBlock {
|
||||
pub(crate) fn consume_blocking_allocation(&self) -> CanBlock {
|
||||
// This flag is the primary point of coordination. The queued flag
|
||||
// happens "around" setting the blocking capacity.
|
||||
BlockingState::consume_allocation(&self.blocking, AcqRel)
|
||||
|
||||
@@ -10,8 +10,8 @@ use std::sync::Arc;
|
||||
/// to poll the future again.
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Waker {
|
||||
pub pool: Arc<Pool>,
|
||||
pub task: Arc<Task>,
|
||||
pub(crate) pool: Arc<Pool>,
|
||||
pub(crate) task: Arc<Task>,
|
||||
}
|
||||
|
||||
unsafe impl Send for Waker {}
|
||||
|
||||
@@ -21,13 +21,13 @@ pub(crate) struct WorkerEntry {
|
||||
//
|
||||
// The `usize` value is deserialized to a `worker::State` instance. See
|
||||
// comments on that type.
|
||||
pub state: CachePadded<AtomicUsize>,
|
||||
pub(crate) state: CachePadded<AtomicUsize>,
|
||||
|
||||
// Next entry in the parked Trieber stack
|
||||
next_sleeper: UnsafeCell<usize>,
|
||||
|
||||
// Worker half of deque
|
||||
pub worker: Worker<Arc<Task>>,
|
||||
pub(crate) worker: Worker<Arc<Task>>,
|
||||
|
||||
// Stealer half of deque
|
||||
stealer: Stealer<Arc<Task>>,
|
||||
@@ -50,7 +50,7 @@ pub(crate) struct WorkerEntry {
|
||||
}
|
||||
|
||||
impl WorkerEntry {
|
||||
pub fn new(park: BoxPark, unpark: BoxUnpark) -> Self {
|
||||
pub(crate) fn new(park: BoxPark, unpark: BoxUnpark) -> Self {
|
||||
let w = Worker::new_fifo();
|
||||
let s = w.stealer();
|
||||
|
||||
@@ -76,14 +76,14 @@ impl WorkerEntry {
|
||||
/// # Ordering
|
||||
///
|
||||
/// The specified ordering is established on the entry's state variable.
|
||||
pub fn fetch_unset_pushed(&self, ordering: Ordering) -> State {
|
||||
pub(crate) fn fetch_unset_pushed(&self, ordering: Ordering) -> State {
|
||||
self.state.fetch_and(!PUSHED_MASK, ordering).into()
|
||||
}
|
||||
|
||||
/// Submit a task to this worker while currently on the same thread that is
|
||||
/// running the worker.
|
||||
#[inline]
|
||||
pub fn submit_internal(&self, task: Arc<Task>) {
|
||||
pub(crate) fn submit_internal(&self, task: Arc<Task>) {
|
||||
self.push_internal(task);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ impl WorkerEntry {
|
||||
///
|
||||
/// The `state` must have been obtained with an `Acquire` ordering.
|
||||
#[inline]
|
||||
pub fn notify(&self, mut state: State) -> bool {
|
||||
pub(crate) fn notify(&self, mut state: State) -> bool {
|
||||
use crate::worker::Lifecycle::*;
|
||||
|
||||
loop {
|
||||
@@ -138,7 +138,7 @@ impl WorkerEntry {
|
||||
/// Returns `Ok` when the worker was successfully signaled.
|
||||
///
|
||||
/// Returns `Err` if the worker has already terminated.
|
||||
pub fn signal_stop(&self, mut state: State) {
|
||||
pub(crate) fn signal_stop(&self, mut state: State) {
|
||||
use crate::worker::Lifecycle::*;
|
||||
|
||||
// Transition the worker state to signaled
|
||||
@@ -189,7 +189,7 @@ impl WorkerEntry {
|
||||
/// This **must** only be called by the thread that owns the worker entry.
|
||||
/// This function is not `Sync`.
|
||||
#[inline]
|
||||
pub fn pop_task(&self) -> Option<Arc<Task>> {
|
||||
pub(crate) fn pop_task(&self) -> Option<Arc<Task>> {
|
||||
self.worker.pop()
|
||||
}
|
||||
|
||||
@@ -201,26 +201,26 @@ impl WorkerEntry {
|
||||
/// At the same time, this method steals some additional tasks and moves
|
||||
/// them into `dest` in order to balance the work distribution among
|
||||
/// workers.
|
||||
pub fn steal_tasks(&self, dest: &Self) -> Steal<Arc<Task>> {
|
||||
pub(crate) fn steal_tasks(&self, dest: &Self) -> Steal<Arc<Task>> {
|
||||
self.stealer.steal_batch_and_pop(&dest.worker)
|
||||
}
|
||||
|
||||
/// Drain (and drop) all tasks that are queued for work.
|
||||
///
|
||||
/// This is called when the pool is shutting down.
|
||||
pub fn drain_tasks(&self) {
|
||||
pub(crate) fn drain_tasks(&self) {
|
||||
while self.worker.pop().is_some() {}
|
||||
}
|
||||
|
||||
/// Parks the worker thread.
|
||||
pub fn park(&self) {
|
||||
pub(crate) fn park(&self) {
|
||||
if let Some(park) = unsafe { (*self.park.get()).as_mut() } {
|
||||
park.park().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Parks the worker thread for at most `duration`.
|
||||
pub fn park_timeout(&self, duration: Duration) {
|
||||
pub(crate) fn park_timeout(&self, duration: Duration) {
|
||||
if let Some(park) = unsafe { (*self.park.get()).as_mut() } {
|
||||
park.park_timeout(duration).unwrap();
|
||||
}
|
||||
@@ -228,7 +228,7 @@ impl WorkerEntry {
|
||||
|
||||
/// Unparks the worker thread.
|
||||
#[inline]
|
||||
pub fn unpark(&self) {
|
||||
pub(crate) fn unpark(&self) {
|
||||
if let Some(park) = unsafe { (*self.unpark.get()).as_ref() } {
|
||||
park.unpark();
|
||||
}
|
||||
@@ -238,7 +238,7 @@ impl WorkerEntry {
|
||||
///
|
||||
/// Called when the task is being polled for the first time.
|
||||
#[inline]
|
||||
pub fn register_task(&self, task: &Arc<Task>) {
|
||||
pub(crate) fn register_task(&self, task: &Arc<Task>) {
|
||||
let running_tasks = unsafe { &mut *self.running_tasks.get() };
|
||||
|
||||
let key = running_tasks.insert(task.clone());
|
||||
@@ -249,7 +249,7 @@ impl WorkerEntry {
|
||||
///
|
||||
/// Called when the task is completed and was previously registered in this worker.
|
||||
#[inline]
|
||||
pub fn unregister_task(&self, task: Arc<Task>) {
|
||||
pub(crate) fn unregister_task(&self, task: Arc<Task>) {
|
||||
let running_tasks = unsafe { &mut *self.running_tasks.get() };
|
||||
running_tasks.remove(task.reg_index.get());
|
||||
self.drain_remotely_completed_tasks();
|
||||
@@ -260,7 +260,7 @@ impl WorkerEntry {
|
||||
/// Called when the task is completed by another worker and was previously registered in this
|
||||
/// worker.
|
||||
#[inline]
|
||||
pub fn remotely_complete_task(&self, task: Arc<Task>) {
|
||||
pub(crate) fn remotely_complete_task(&self, task: Arc<Task>) {
|
||||
self.remotely_completed_tasks.push(task);
|
||||
self.needs_drain.store(true, Release);
|
||||
}
|
||||
@@ -268,7 +268,7 @@ impl WorkerEntry {
|
||||
/// Drops the remaining incomplete tasks and the parker associated with this worker.
|
||||
///
|
||||
/// This function is called by the shutdown trigger.
|
||||
pub fn shutdown(&self) {
|
||||
pub(crate) fn shutdown(&self) {
|
||||
self.drain_remotely_completed_tasks();
|
||||
|
||||
// Abort all incomplete tasks.
|
||||
@@ -297,17 +297,17 @@ impl WorkerEntry {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push_internal(&self, task: Arc<Task>) {
|
||||
pub(crate) fn push_internal(&self, task: Arc<Task>) {
|
||||
self.worker.push(task);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn next_sleeper(&self) -> usize {
|
||||
pub(crate) fn next_sleeper(&self) -> usize {
|
||||
unsafe { *self.next_sleeper.get() }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_next_sleeper(&self, val: usize) {
|
||||
pub(crate) fn set_next_sleeper(&self, val: usize) {
|
||||
unsafe {
|
||||
*self.next_sleeper.get() = val;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ const ABA_GUARD_MASK: usize = (1 << (32 - ABA_GUARD_SHIFT)) - 1;
|
||||
|
||||
impl Stack {
|
||||
/// Create a new `Stack` representing the empty state.
|
||||
pub fn new() -> Stack {
|
||||
pub(crate) fn new() -> Stack {
|
||||
let state = AtomicUsize::new(State::new().into());
|
||||
Stack { state }
|
||||
}
|
||||
@@ -71,7 +71,7 @@ impl Stack {
|
||||
///
|
||||
/// Returns `Err` if the pool has transitioned to the `TERMINATED` state.
|
||||
/// When terminated, pushing new entries is no longer permitted.
|
||||
pub fn push(&self, entries: &[worker::Entry], idx: usize) -> Result<(), ()> {
|
||||
pub(crate) fn push(&self, entries: &[worker::Entry], idx: usize) -> Result<(), ()> {
|
||||
let mut state: State = self.state.load(Acquire).into();
|
||||
|
||||
debug_assert!(worker::State::from(entries[idx].state.load(Relaxed)).is_pushed());
|
||||
@@ -113,7 +113,7 @@ impl Stack {
|
||||
/// Returns the index of the popped worker and the worker's observed state.
|
||||
///
|
||||
/// `None` if the stack is empty.
|
||||
pub fn pop(
|
||||
pub(crate) fn pop(
|
||||
&self,
|
||||
entries: &[worker::Entry],
|
||||
max_lifecycle: worker::Lifecycle,
|
||||
|
||||
@@ -35,15 +35,15 @@ pub(crate) enum Lifecycle {
|
||||
|
||||
impl State {
|
||||
/// Returns true if the worker entry is pushed in the sleeper stack
|
||||
pub fn is_pushed(self) -> bool {
|
||||
pub(crate) fn is_pushed(self) -> bool {
|
||||
self.0 & PUSHED_MASK == PUSHED_MASK
|
||||
}
|
||||
|
||||
pub fn set_pushed(&mut self) {
|
||||
pub(crate) fn set_pushed(&mut self) {
|
||||
self.0 |= PUSHED_MASK
|
||||
}
|
||||
|
||||
pub fn is_notified(self) -> bool {
|
||||
pub(crate) fn is_notified(self) -> bool {
|
||||
use self::Lifecycle::*;
|
||||
|
||||
match self.lifecycle() {
|
||||
@@ -52,19 +52,19 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lifecycle(self) -> Lifecycle {
|
||||
pub(crate) fn lifecycle(self) -> Lifecycle {
|
||||
Lifecycle::from(self.0 & LIFECYCLE_MASK)
|
||||
}
|
||||
|
||||
pub fn set_lifecycle(&mut self, val: Lifecycle) {
|
||||
pub(crate) fn set_lifecycle(&mut self, val: Lifecycle) {
|
||||
self.0 = (self.0 & !LIFECYCLE_MASK) | (val as usize)
|
||||
}
|
||||
|
||||
pub fn is_signaled(self) -> bool {
|
||||
pub(crate) fn is_signaled(self) -> bool {
|
||||
self.lifecycle() == Lifecycle::Signaled
|
||||
}
|
||||
|
||||
pub fn notify(&mut self) {
|
||||
pub(crate) fn notify(&mut self) {
|
||||
use self::Lifecycle::Signaled;
|
||||
|
||||
if self.lifecycle() != Signaled {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-timer/0.3.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ pub(crate) struct AtomicStackEntries {
|
||||
const SHUTDOWN: *mut Entry = 1 as *mut _;
|
||||
|
||||
impl AtomicStack {
|
||||
pub fn new() -> AtomicStack {
|
||||
pub(crate) fn new() -> AtomicStack {
|
||||
AtomicStack {
|
||||
head: AtomicPtr::new(ptr::null_mut()),
|
||||
}
|
||||
@@ -32,7 +32,7 @@ impl AtomicStack {
|
||||
///
|
||||
/// Returns `true` if the entry was pushed, `false` if the entry is already
|
||||
/// on the stack, `Err` if the timer is shutdown.
|
||||
pub fn push(&self, entry: &Arc<Entry>) -> Result<bool, Error> {
|
||||
pub(crate) fn push(&self, entry: &Arc<Entry>) -> Result<bool, Error> {
|
||||
// First, set the queued bit on the entry
|
||||
let queued = entry.queued.fetch_or(true, SeqCst);
|
||||
|
||||
@@ -72,14 +72,14 @@ impl AtomicStack {
|
||||
}
|
||||
|
||||
/// Take all entries from the stack
|
||||
pub fn take(&self) -> AtomicStackEntries {
|
||||
pub(crate) fn take(&self) -> AtomicStackEntries {
|
||||
let ptr = self.head.swap(ptr::null_mut(), SeqCst);
|
||||
AtomicStackEntries { ptr }
|
||||
}
|
||||
|
||||
/// Drain all remaining nodes in the stack and prevent any new nodes from
|
||||
/// being pushed onto the stack.
|
||||
pub fn shutdown(&self) {
|
||||
pub(crate) fn shutdown(&self) {
|
||||
// Shutdown the processing queue
|
||||
let ptr = self.head.swap(SHUTDOWN, SeqCst);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ const ERROR: u64 = u64::MAX;
|
||||
// ===== impl Entry =====
|
||||
|
||||
impl Entry {
|
||||
pub fn new(deadline: Instant, duration: Duration) -> Entry {
|
||||
pub(crate) fn new(deadline: Instant, duration: Duration) -> Entry {
|
||||
Entry {
|
||||
time: CachePadded::new(UnsafeCell::new(Time { deadline, duration })),
|
||||
inner: None,
|
||||
@@ -119,24 +119,24 @@ impl Entry {
|
||||
}
|
||||
|
||||
/// Only called by `Registration`
|
||||
pub fn time_ref(&self) -> &Time {
|
||||
pub(crate) fn time_ref(&self) -> &Time {
|
||||
unsafe { &*self.time.get() }
|
||||
}
|
||||
|
||||
/// Only called by `Registration`
|
||||
#[allow(clippy::mut_from_ref)] // https://github.com/rust-lang/rust-clippy/issues/4281
|
||||
pub unsafe fn time_mut(&self) -> &mut Time {
|
||||
pub(crate) unsafe fn time_mut(&self) -> &mut Time {
|
||||
&mut *self.time.get()
|
||||
}
|
||||
|
||||
/// Returns `true` if the `Entry` is currently associated with a timer
|
||||
/// instance.
|
||||
pub fn is_registered(&self) -> bool {
|
||||
pub(crate) fn is_registered(&self) -> bool {
|
||||
self.inner.is_some()
|
||||
}
|
||||
|
||||
/// Only called by `Registration`
|
||||
pub fn register(me: &mut Arc<Self>) {
|
||||
pub(crate) fn register(me: &mut Arc<Self>) {
|
||||
let handle = match HandlePriv::try_current() {
|
||||
Ok(handle) => handle,
|
||||
Err(_) => {
|
||||
@@ -152,7 +152,7 @@ impl Entry {
|
||||
}
|
||||
|
||||
/// Only called by `Registration`
|
||||
pub fn register_with(me: &mut Arc<Self>, handle: HandlePriv) {
|
||||
pub(crate) fn register_with(me: &mut Arc<Self>, handle: HandlePriv) {
|
||||
assert!(!me.is_registered(), "only register an entry once");
|
||||
|
||||
let deadline = me.time_ref().deadline;
|
||||
@@ -202,18 +202,18 @@ impl Entry {
|
||||
|
||||
/// The current entry state as known by the timer. This is not the value of
|
||||
/// `state`, but lets the timer know how to converge its state to `state`.
|
||||
pub fn when_internal(&self) -> Option<u64> {
|
||||
pub(crate) fn when_internal(&self) -> Option<u64> {
|
||||
unsafe { (*self.when.get()) }
|
||||
}
|
||||
|
||||
pub fn set_when_internal(&self, when: Option<u64>) {
|
||||
pub(crate) fn set_when_internal(&self, when: Option<u64>) {
|
||||
unsafe {
|
||||
(*self.when.get()) = when;
|
||||
}
|
||||
}
|
||||
|
||||
/// Called by `Timer` to load the current value of `state` for processing
|
||||
pub fn load_state(&self) -> Option<u64> {
|
||||
pub(crate) fn load_state(&self) -> Option<u64> {
|
||||
let state = self.state.load(SeqCst);
|
||||
|
||||
if is_elapsed(state) {
|
||||
@@ -223,12 +223,12 @@ impl Entry {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_elapsed(&self) -> bool {
|
||||
pub(crate) fn is_elapsed(&self) -> bool {
|
||||
let state = self.state.load(SeqCst);
|
||||
is_elapsed(state)
|
||||
}
|
||||
|
||||
pub fn fire(&self, when: u64) {
|
||||
pub(crate) fn fire(&self, when: u64) {
|
||||
let mut curr = self.state.load(SeqCst);
|
||||
|
||||
loop {
|
||||
@@ -249,7 +249,7 @@ impl Entry {
|
||||
self.waker.wake();
|
||||
}
|
||||
|
||||
pub fn error(&self) {
|
||||
pub(crate) fn error(&self) {
|
||||
// Only transition to the error state if not currently elapsed
|
||||
let mut curr = self.state.load(SeqCst);
|
||||
|
||||
@@ -272,7 +272,7 @@ impl Entry {
|
||||
self.waker.wake();
|
||||
}
|
||||
|
||||
pub fn cancel(entry: &Arc<Entry>) {
|
||||
pub(crate) fn cancel(entry: &Arc<Entry>) {
|
||||
let state = entry.state.fetch_or(ELAPSED, SeqCst);
|
||||
|
||||
if is_elapsed(state) {
|
||||
@@ -289,7 +289,7 @@ impl Entry {
|
||||
let _ = inner.queue(entry);
|
||||
}
|
||||
|
||||
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||
pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||
let mut curr = self.state.load(SeqCst);
|
||||
|
||||
if is_elapsed(curr) {
|
||||
@@ -316,7 +316,7 @@ impl Entry {
|
||||
}
|
||||
|
||||
/// Only called by `Registration`
|
||||
pub fn reset(entry: &mut Arc<Entry>) {
|
||||
pub(crate) fn reset(entry: &mut Arc<Entry>) {
|
||||
if !entry.is_registered() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -7,4 +7,5 @@ pub trait Now {
|
||||
fn now(&mut self) -> Instant;
|
||||
}
|
||||
|
||||
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
|
||||
pub use crate::clock::Clock as SystemNow;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub(crate) struct Registration {
|
||||
}
|
||||
|
||||
impl Registration {
|
||||
pub fn new(deadline: Instant, duration: Duration) -> Registration {
|
||||
pub(crate) fn new(deadline: Instant, duration: Duration) -> Registration {
|
||||
fn is_send<T: Send + Sync>() {}
|
||||
is_send::<Registration>();
|
||||
|
||||
@@ -23,21 +23,21 @@ impl Registration {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deadline(&self) -> Instant {
|
||||
pub(crate) fn deadline(&self) -> Instant {
|
||||
self.entry.time_ref().deadline
|
||||
}
|
||||
|
||||
pub fn register(&mut self) {
|
||||
pub(crate) fn register(&mut self) {
|
||||
if !self.entry.is_registered() {
|
||||
Entry::register(&mut self.entry)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_with(&mut self, handle: HandlePriv) {
|
||||
pub(crate) fn register_with(&mut self, handle: HandlePriv) {
|
||||
Entry::register_with(&mut self.entry, handle)
|
||||
}
|
||||
|
||||
pub fn reset(&mut self, deadline: Instant) {
|
||||
pub(crate) fn reset(&mut self, deadline: Instant) {
|
||||
unsafe {
|
||||
self.entry.time_mut().deadline = deadline;
|
||||
}
|
||||
@@ -46,7 +46,7 @@ impl Registration {
|
||||
|
||||
// Used by `Timeout<Stream>`
|
||||
#[cfg(feature = "async-traits")]
|
||||
pub fn reset_timeout(&mut self) {
|
||||
pub(crate) fn reset_timeout(&mut self) {
|
||||
let deadline = crate::clock::now() + self.entry.time_ref().duration;
|
||||
unsafe {
|
||||
self.entry.time_mut().deadline = deadline;
|
||||
@@ -54,11 +54,11 @@ impl Registration {
|
||||
Entry::reset(&mut self.entry);
|
||||
}
|
||||
|
||||
pub fn is_elapsed(&self) -> bool {
|
||||
pub(crate) fn is_elapsed(&self) -> bool {
|
||||
self.entry.is_elapsed()
|
||||
}
|
||||
|
||||
pub fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||
pub(crate) fn poll_elapsed(&self, cx: &mut task::Context<'_>) -> Poll<Result<(), Error>> {
|
||||
self.entry.poll_elapsed(cx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ pub(crate) struct Level<T> {
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Expiration {
|
||||
/// The level containing the slot.
|
||||
pub level: usize,
|
||||
pub(crate) level: usize,
|
||||
|
||||
/// The slot index.
|
||||
pub slot: usize,
|
||||
pub(crate) slot: usize,
|
||||
|
||||
/// The instant at which the slot needs to be processed.
|
||||
pub deadline: u64,
|
||||
pub(crate) deadline: u64,
|
||||
}
|
||||
|
||||
/// Level multiplier.
|
||||
@@ -37,7 +37,7 @@ pub(crate) struct Expiration {
|
||||
const LEVEL_MULT: usize = 64;
|
||||
|
||||
impl<T: Stack> Level<T> {
|
||||
pub fn new(level: usize) -> Level<T> {
|
||||
pub(crate) fn new(level: usize) -> Level<T> {
|
||||
// Rust's derived implementations for arrays require that the value
|
||||
// contained by the array be `Copy`. So, here we have to manually
|
||||
// initialize every single slot.
|
||||
@@ -123,7 +123,7 @@ impl<T: Stack> Level<T> {
|
||||
|
||||
/// Finds the slot that needs to be processed next and returns the slot and
|
||||
/// `Instant` at which this slot must be processed.
|
||||
pub fn next_expiration(&self, now: u64) -> Option<Expiration> {
|
||||
pub(crate) fn next_expiration(&self, now: u64) -> Option<Expiration> {
|
||||
// Use the `occupied` bit field to get the index of the next slot that
|
||||
// needs to be processed.
|
||||
let slot = match self.next_occupied_slot(now) {
|
||||
@@ -172,14 +172,14 @@ impl<T: Stack> Level<T> {
|
||||
Some(slot)
|
||||
}
|
||||
|
||||
pub fn add_entry(&mut self, when: u64, item: T::Owned, store: &mut T::Store) {
|
||||
pub(crate) fn add_entry(&mut self, when: u64, item: T::Owned, store: &mut T::Store) {
|
||||
let slot = slot_for(when, self.level);
|
||||
|
||||
self.slot[slot].push(item, store);
|
||||
self.occupied |= occupied_bit(slot);
|
||||
}
|
||||
|
||||
pub fn remove_entry(&mut self, when: u64, item: &T::Borrowed, store: &mut T::Store) {
|
||||
pub(crate) fn remove_entry(&mut self, when: u64, item: &T::Borrowed, store: &mut T::Store) {
|
||||
let slot = slot_for(when, self.level);
|
||||
|
||||
self.slot[slot].remove(item, store);
|
||||
@@ -193,7 +193,7 @@ impl<T: Stack> Level<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option<T::Owned> {
|
||||
pub(crate) fn pop_entry_slot(&mut self, slot: usize, store: &mut T::Store) -> Option<T::Owned> {
|
||||
let ret = self.slot[slot].pop(store);
|
||||
|
||||
if ret.is_some() && self.slot[slot].is_empty() {
|
||||
|
||||
@@ -63,7 +63,7 @@ where
|
||||
T: Stack,
|
||||
{
|
||||
/// Create a new timing wheel
|
||||
pub fn new() -> Wheel<T> {
|
||||
pub(crate) fn new() -> Wheel<T> {
|
||||
let levels = (0..NUM_LEVELS).map(Level::new).collect();
|
||||
|
||||
Wheel { elapsed: 0, levels }
|
||||
@@ -71,7 +71,7 @@ where
|
||||
|
||||
/// Return the number of milliseconds that have elapsed since the timing
|
||||
/// wheel's creation.
|
||||
pub fn elapsed(&self) -> u64 {
|
||||
pub(crate) fn elapsed(&self) -> u64 {
|
||||
self.elapsed
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ where
|
||||
/// immediately.
|
||||
///
|
||||
/// `Err(Invalid)` indicates an invalid `when` argument as been supplied.
|
||||
pub fn insert(
|
||||
pub(crate) fn insert(
|
||||
&mut self,
|
||||
when: u64,
|
||||
item: T::Owned,
|
||||
@@ -124,7 +124,7 @@ where
|
||||
}
|
||||
|
||||
/// Remove `item` from thee timing wheel.
|
||||
pub fn remove(&mut self, item: &T::Borrowed, store: &mut T::Store) {
|
||||
pub(crate) fn remove(&mut self, item: &T::Borrowed, store: &mut T::Store) {
|
||||
let when = T::when(item, store);
|
||||
let level = self.level_for(when);
|
||||
|
||||
@@ -132,11 +132,11 @@ where
|
||||
}
|
||||
|
||||
/// Instant at which to poll
|
||||
pub fn poll_at(&self) -> Option<u64> {
|
||||
pub(crate) fn poll_at(&self) -> Option<u64> {
|
||||
self.next_expiration().map(|expiration| expiration.deadline)
|
||||
}
|
||||
|
||||
pub fn poll(&mut self, poll: &mut Poll, store: &mut T::Store) -> Option<T::Owned> {
|
||||
pub(crate) fn poll(&mut self, poll: &mut Poll, store: &mut T::Store) -> Option<T::Owned> {
|
||||
loop {
|
||||
if poll.expiration.is_none() {
|
||||
poll.expiration = self.next_expiration().and_then(|expiration| {
|
||||
@@ -194,7 +194,7 @@ where
|
||||
None
|
||||
}
|
||||
|
||||
pub fn poll_expiration(
|
||||
pub(crate) fn poll_expiration(
|
||||
&mut self,
|
||||
expiration: &Expiration,
|
||||
store: &mut T::Store,
|
||||
@@ -249,7 +249,7 @@ fn level_for(elapsed: u64, when: u64) -> usize {
|
||||
}
|
||||
|
||||
impl Poll {
|
||||
pub fn new(now: u64) -> Poll {
|
||||
pub(crate) fn new(now: u64) -> Poll {
|
||||
Poll {
|
||||
now,
|
||||
expiration: None,
|
||||
|
||||
+19
-1
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-tls/0.3.0-alpha.1")]
|
||||
#![warn(rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
@@ -21,6 +26,7 @@
|
||||
//! `native-tls` crate.
|
||||
|
||||
use native_tls::{Error, HandshakeError, MidHandshakeTlsStream};
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::marker::Unpin;
|
||||
@@ -270,6 +276,12 @@ impl TlsConnector {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TlsConnector {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("TlsConnector").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<native_tls::TlsConnector> for TlsConnector {
|
||||
fn from(inner: native_tls::TlsConnector) -> TlsConnector {
|
||||
TlsConnector(inner)
|
||||
@@ -295,6 +307,12 @@ impl TlsAcceptor {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TlsAcceptor {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("TlsAcceptor").finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<native_tls::TlsAcceptor> for TlsAcceptor {
|
||||
fn from(inner: native_tls::TlsAcceptor) -> TlsAcceptor {
|
||||
TlsAcceptor(inner)
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-tcp/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
#![cfg(unix)]
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-uds/0.3.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct UCred {
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub use self::impl_linux::get_peer_cred;
|
||||
pub(crate) use self::impl_linux::get_peer_cred;
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "dragonfly",
|
||||
@@ -20,20 +20,20 @@ pub use self::impl_linux::get_peer_cred;
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
pub use self::impl_macos::get_peer_cred;
|
||||
pub(crate) use self::impl_macos::get_peer_cred;
|
||||
|
||||
#[cfg(any(target_os = "solaris"))]
|
||||
pub use self::impl_solaris::get_peer_cred;
|
||||
pub(crate) use self::impl_solaris::get_peer_cred;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
pub mod impl_linux {
|
||||
pub(crate) mod impl_linux {
|
||||
use crate::UnixStream;
|
||||
use libc::{c_void, getsockopt, socklen_t, SOL_SOCKET, SO_PEERCRED};
|
||||
use std::{io, mem};
|
||||
|
||||
use libc::ucred;
|
||||
|
||||
pub fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||
pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
unsafe {
|
||||
@@ -80,14 +80,14 @@ pub mod impl_linux {
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
pub mod impl_macos {
|
||||
pub(crate) mod impl_macos {
|
||||
use crate::UnixStream;
|
||||
use libc::getpeereid;
|
||||
use std::io;
|
||||
use std::mem::MaybeUninit;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
|
||||
pub fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||
pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||
unsafe {
|
||||
let raw_fd = sock.as_raw_fd();
|
||||
|
||||
@@ -109,7 +109,7 @@ pub mod impl_macos {
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "solaris"))]
|
||||
pub mod impl_solaris {
|
||||
pub(crate) mod impl_solaris {
|
||||
use std::io;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::ptr;
|
||||
@@ -129,7 +129,7 @@ pub mod impl_solaris {
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
|
||||
pub fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||
pub(crate) fn get_peer_cred(sock: &UnixStream) -> io::Result<super::UCred> {
|
||||
unsafe {
|
||||
let raw_fd = sock.as_raw_fd();
|
||||
|
||||
|
||||
+6
-1
@@ -1,5 +1,10 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio/0.2.0-alpha.1")]
|
||||
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
|
||||
#![warn(
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
rust_2018_idioms,
|
||||
unreachable_pub
|
||||
)]
|
||||
#![doc(test(no_crate_inject, attr(deny(rust_2018_idioms))))]
|
||||
#![feature(async_await)]
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@ use tokio_timer::timer::{self, Timer};
|
||||
use std::{io, thread};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Background {
|
||||
pub(crate) struct Background {
|
||||
reactor_handle: tokio_reactor::Handle,
|
||||
timer_handle: timer::Handle,
|
||||
shutdown_tx: Option<oneshot::Sender<()>>,
|
||||
thread: Option<thread::JoinHandle<()>>,
|
||||
}
|
||||
|
||||
pub fn spawn(clock: &Clock) -> io::Result<Background> {
|
||||
pub(crate) fn spawn(clock: &Clock) -> io::Result<Background> {
|
||||
let clock = clock.clone();
|
||||
|
||||
let reactor = Reactor::new()?;
|
||||
|
||||
@@ -2,7 +2,9 @@ mod background;
|
||||
mod builder;
|
||||
mod task_executor;
|
||||
|
||||
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
|
||||
pub use self::builder::Builder;
|
||||
#[allow(unreachable_pub)] // https://github.com/rust-lang/rust/issues/57411
|
||||
pub use self::task_executor::TaskExecutor;
|
||||
use background::Background;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user