mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
v0.1.x: prepare to release new reactor, executor, and timer (#1751)
This commit is contained in:
committed by
Carl Lerche
parent
96b014c12a
commit
97565c0e75
@@ -1,3 +1,9 @@
|
|||||||
|
# 0.1.9 (November 27, 2019)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- Add `executor::set_default` which behaves like `with_default` but returns a
|
||||||
|
drop guard (#1725).
|
||||||
|
|
||||||
# 0.1.8 (June 2, 2019)
|
# 0.1.8 (June 2, 2019)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ name = "tokio-executor"
|
|||||||
# - README.md
|
# - README.md
|
||||||
# - Update CHANGELOG.md.
|
# - Update CHANGELOG.md.
|
||||||
# - Create "v0.1.x" git tag.
|
# - Create "v0.1.x" git tag.
|
||||||
version = "0.1.8"
|
version = "0.1.9"
|
||||||
documentation = "https://docs.rs/tokio-executor/0.1.7/tokio_executor"
|
documentation = "https://docs.rs/tokio-executor/0.1.9/tokio_executor"
|
||||||
repository = "https://github.com/tokio-rs/tokio"
|
repository = "https://github.com/tokio-rs/tokio"
|
||||||
homepage = "https://github.com/tokio-rs/tokio"
|
homepage = "https://github.com/tokio-rs/tokio"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Task execution related traits and utilities.
|
Task execution related traits and utilities.
|
||||||
|
|
||||||
[Documentation](https://docs.rs/tokio-executor/0.1.8/tokio_executor)
|
[Documentation](https://docs.rs/tokio-executor/0.1.9/tokio_executor)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ executor, including:
|
|||||||
|
|
||||||
* [`Park`] abstracts over blocking and unblocking the current thread.
|
* [`Park`] abstracts over blocking and unblocking the current thread.
|
||||||
|
|
||||||
[`Executor`]: https://docs.rs/tokio-executor/0.1.8/tokio_executor/trait.Executor.html
|
[`Executor`]: https://docs.rs/tokio-executor/0.1.9/tokio_executor/trait.Executor.html
|
||||||
[`enter`]: https://docs.rs/tokio-executor/0.1.8/tokio_executor/fn.enter.html
|
[`enter`]: https://docs.rs/tokio-executor/0.1.9/tokio_executor/fn.enter.html
|
||||||
[`DefaultExecutor`]: https://docs.rs/tokio-executor/0.1.8/tokio_executor/struct.DefaultExecutor.html
|
[`DefaultExecutor`]: https://docs.rs/tokio-executor/0.1.9/tokio_executor/struct.DefaultExecutor.html
|
||||||
[`Park`]: https://docs.rs/tokio-executor/0.1.8/tokio_executor/park/trait.Park.html
|
[`Park`]: https://docs.rs/tokio-executor/0.1.9/tokio_executor/park/trait.Park.html
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use super::{Enter, Executor, SpawnError};
|
|||||||
use futures::{future, Future};
|
use futures::{future, Future};
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
/// Executes futures on the default executor for the current execution context.
|
/// Executes futures on the default executor for the current execution context.
|
||||||
///
|
///
|
||||||
@@ -23,8 +22,8 @@ pub struct DefaultExecutor {
|
|||||||
/// Ensures that the executor is removed from the thread-local context
|
/// Ensures that the executor is removed from the thread-local context
|
||||||
/// when leaving the scope. This handles cases that involve panicking.
|
/// when leaving the scope. This handles cases that involve panicking.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DefaultGuard<'a> {
|
pub struct DefaultGuard {
|
||||||
_lifetime: PhantomData<&'a ()>,
|
_p: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DefaultExecutor {
|
impl DefaultExecutor {
|
||||||
@@ -183,20 +182,11 @@ where
|
|||||||
T: Executor,
|
T: Executor,
|
||||||
F: FnOnce(&mut Enter) -> R,
|
F: FnOnce(&mut Enter) -> R,
|
||||||
{
|
{
|
||||||
let _guard = set_default(executor);
|
unsafe fn hide_lt<'a>(p: *mut (dyn Executor + 'a)) -> *mut (dyn Executor + 'static) {
|
||||||
f(enter)
|
use std::mem;
|
||||||
}
|
mem::transmute(p)
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets `executor` as the default executor, returning a guard that unsets it when
|
|
||||||
/// dropped.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This function panics if there already is a default executor set.
|
|
||||||
pub fn set_default<T>(executor: &mut T) -> DefaultGuard<'_>
|
|
||||||
where
|
|
||||||
T: Executor,
|
|
||||||
{
|
|
||||||
EXECUTOR.with(|cell| {
|
EXECUTOR.with(|cell| {
|
||||||
match cell.get() {
|
match cell.get() {
|
||||||
State::Ready(_) | State::Active => {
|
State::Ready(_) | State::Active => {
|
||||||
@@ -205,6 +195,18 @@ where
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that the executor is removed from the thread-local context
|
||||||
|
// when leaving the scope. This handles cases that involve panicking.
|
||||||
|
struct Reset<'a>(&'a Cell<State>);
|
||||||
|
|
||||||
|
impl<'a> Drop for Reset<'a> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.0.set(State::Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let _reset = Reset(cell);
|
||||||
|
|
||||||
// While scary, this is safe. The function takes a
|
// While scary, this is safe. The function takes a
|
||||||
// `&mut Executor`, which guarantees that the reference lives for the
|
// `&mut Executor`, which guarantees that the reference lives for the
|
||||||
// duration of `with_default`.
|
// duration of `with_default`.
|
||||||
@@ -215,22 +217,50 @@ where
|
|||||||
let executor = unsafe { hide_lt(executor as &mut _ as *mut _) };
|
let executor = unsafe { hide_lt(executor as &mut _ as *mut _) };
|
||||||
|
|
||||||
cell.set(State::Ready(executor));
|
cell.set(State::Ready(executor));
|
||||||
|
|
||||||
|
f(enter)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets `executor` as the default executor, returning a guard that unsets it when
|
||||||
|
/// dropped.
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This function panics if there already is a default executor set.
|
||||||
|
pub fn set_default<T>(executor: T) -> DefaultGuard
|
||||||
|
where
|
||||||
|
T: Executor + 'static,
|
||||||
|
{
|
||||||
|
EXECUTOR.with(|cell| {
|
||||||
|
match cell.get() {
|
||||||
|
State::Ready(_) | State::Active => {
|
||||||
|
panic!("default executor already set for execution context")
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that the executor will outlive the call to set_default, even
|
||||||
|
// if the drop guard is never dropped due to calls to `mem::forget` or
|
||||||
|
// similar.
|
||||||
|
let executor = Box::new(executor);
|
||||||
|
|
||||||
|
cell.set(State::Ready(Box::into_raw(executor)));
|
||||||
});
|
});
|
||||||
|
|
||||||
DefaultGuard {
|
DefaultGuard { _p: () }
|
||||||
_lifetime: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn hide_lt<'a>(p: *mut (dyn Executor + 'a)) -> *mut (dyn Executor + 'static) {
|
impl Drop for DefaultGuard {
|
||||||
use std::mem;
|
|
||||||
mem::transmute(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for DefaultGuard<'a> {
|
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = EXECUTOR.try_with(|cell| {
|
let _ = EXECUTOR.try_with(|cell| {
|
||||||
cell.set(State::Empty);
|
if let State::Ready(prev) = cell.replace(State::Empty) {
|
||||||
|
// drop the previous executor.
|
||||||
|
unsafe {
|
||||||
|
let prev = Box::from_raw(prev);
|
||||||
|
drop(prev);
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#![deny(missing_docs, missing_debug_implementations)]
|
#![deny(missing_docs, missing_debug_implementations)]
|
||||||
#![doc(html_root_url = "https://docs.rs/tokio-executor/0.1.8")]
|
#![doc(html_root_url = "https://docs.rs/tokio-executor/0.1.9")]
|
||||||
|
|
||||||
//! Task execution related traits and utilities.
|
//! Task execution related traits and utilities.
|
||||||
//!
|
//!
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
# 0.1.11 (November 27, 2019)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `set_default`, which functions like `with_default` but returns a drop
|
||||||
|
guard (#1725)
|
||||||
|
|
||||||
# 0.1.10 (September 25, 2019)
|
# 0.1.10 (September 25, 2019)
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|||||||
@@ -8,13 +8,13 @@ name = "tokio-reactor"
|
|||||||
# - README.md
|
# - README.md
|
||||||
# - Update CHANGELOG.md.
|
# - Update CHANGELOG.md.
|
||||||
# - Create "v0.1.x" git tag.
|
# - Create "v0.1.x" git tag.
|
||||||
version = "0.1.10"
|
version = "0.1.11"
|
||||||
authors = ["Carl Lerche <[email protected]>"]
|
authors = ["Carl Lerche <[email protected]>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/tokio-rs/tokio"
|
repository = "https://github.com/tokio-rs/tokio"
|
||||||
homepage = "https://tokio.rs"
|
homepage = "https://tokio.rs"
|
||||||
documentation = "https://docs.rs/tokio-reactor/0.1.10/tokio_reactor"
|
documentation = "https://docs.rs/tokio-reactor/0.1.11/tokio_reactor"
|
||||||
description = """
|
description = """
|
||||||
Event loop that drives Tokio I/O resources.
|
Event loop that drives Tokio I/O resources.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Event loop that drives Tokio I/O resources.
|
Event loop that drives Tokio I/O resources.
|
||||||
|
|
||||||
[Documentation](https://docs.rs/tokio-reactor/0.1.10/tokio_reactor)
|
[Documentation](https://docs.rs/tokio-reactor/0.1.11/tokio_reactor)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ are building a custom I/O resource.
|
|||||||
|
|
||||||
[`mio`]: http://github.com/carllerche/mio
|
[`mio`]: http://github.com/carllerche/mio
|
||||||
[`futures`]: http://github.com/rust-lang-nursery/futures-rs
|
[`futures`]: http://github.com/rust-lang-nursery/futures-rs
|
||||||
[`Reactor`]: https://docs.rs/tokio-reactor/0.1.10/tokio_reactor/struct.Reactor.html
|
[`Reactor`]: https://docs.rs/tokio-reactor/0.1.11/tokio_reactor/struct.Reactor.html
|
||||||
[`Handle`]: https://docs.rs/tokio-reactor/0.1.10/tokio_reactor/struct.Handle.html
|
[`Handle`]: https://docs.rs/tokio-reactor/0.1.11/tokio_reactor/struct.Handle.html
|
||||||
[`Registration`]: https://docs.rs/tokio-reactor/0.1.10/tokio_reactor/struct.Registration.html
|
[`Registration`]: https://docs.rs/tokio-reactor/0.1.11/tokio_reactor/struct.Registration.html
|
||||||
[`PollEvented`]: https://docs.rs/tokio-reactor/0.1.10/tokio_reactor/struct.PollEvented.html
|
[`PollEvented`]: https://docs.rs/tokio-reactor/0.1.11/tokio_reactor/struct.PollEvented.html
|
||||||
[`tokio`]: ../
|
[`tokio`]: ../
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#![doc(html_root_url = "https://docs.rs/tokio-reactor/0.1.10")]
|
#![doc(html_root_url = "https://docs.rs/tokio-reactor/0.1.11")]
|
||||||
#![deny(missing_docs, missing_debug_implementations)]
|
#![deny(missing_docs, missing_debug_implementations)]
|
||||||
|
|
||||||
//! Event loop that drives Tokio I/O resources.
|
//! Event loop that drives Tokio I/O resources.
|
||||||
@@ -68,7 +68,6 @@ use tokio_sync::task::AtomicTask;
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
#[cfg(all(unix, not(target_os = "fuchsia")))]
|
#[cfg(all(unix, not(target_os = "fuchsia")))]
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
@@ -137,8 +136,8 @@ pub type SetDefaultError = SetFallbackError;
|
|||||||
/// Ensure that the default reactor is removed from the thread-local context
|
/// Ensure that the default reactor is removed from the thread-local context
|
||||||
/// when leaving the scope. This handles cases that involve panicking.
|
/// when leaving the scope. This handles cases that involve panicking.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DefaultGuard<'a> {
|
pub struct DefaultGuard {
|
||||||
_lifetime: PhantomData<&'a ()>,
|
_p: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -217,7 +216,7 @@ where
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// This function panics if there already is a default reactor set.
|
/// This function panics if there already is a default reactor set.
|
||||||
pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
|
pub fn set_default(handle: &Handle) -> DefaultGuard {
|
||||||
CURRENT_REACTOR.with(|current| {
|
CURRENT_REACTOR.with(|current| {
|
||||||
let mut current = current.borrow_mut();
|
let mut current = current.borrow_mut();
|
||||||
|
|
||||||
@@ -236,9 +235,7 @@ pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
|
|||||||
|
|
||||||
*current = Some(handle.clone());
|
*current = Some(handle.clone());
|
||||||
});
|
});
|
||||||
DefaultGuard {
|
DefaultGuard { _p: () }
|
||||||
_lifetime: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reactor {
|
impl Reactor {
|
||||||
@@ -746,7 +743,7 @@ impl Direction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for DefaultGuard<'a> {
|
impl Drop for DefaultGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = CURRENT_REACTOR.try_with(|current| {
|
let _ = CURRENT_REACTOR.try_with(|current| {
|
||||||
let mut current = current.borrow_mut();
|
let mut current = current.borrow_mut();
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
# 0.2.12 (November 27, 2019)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- `timer::set_default`, which functions like `timer::with_default`, but
|
||||||
|
returns a drop guard (#1725).
|
||||||
|
- `clock::set_default`, which functions like `clock::with_default`, but
|
||||||
|
returns a drop guard (#1725).
|
||||||
|
|
||||||
# 0.2.11 (May 14, 2019)
|
# 0.2.11 (May 14, 2019)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ name = "tokio-timer"
|
|||||||
# - README.md
|
# - README.md
|
||||||
# - Update CHANGELOG.md.
|
# - Update CHANGELOG.md.
|
||||||
# - Create "v0.2.x" git tag.
|
# - Create "v0.2.x" git tag.
|
||||||
version = "0.2.11"
|
version = "0.2.12"
|
||||||
authors = ["Carl Lerche <[email protected]>"]
|
authors = ["Carl Lerche <[email protected]>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
documentation = "https://docs.rs/tokio-timer/0.2.11/tokio_timer"
|
documentation = "https://docs.rs/tokio-timer/0.2.12/tokio_timer"
|
||||||
repository = "https://github.com/tokio-rs/tokio"
|
repository = "https://github.com/tokio-rs/tokio"
|
||||||
homepage = "https://github.com/tokio-rs/tokio"
|
homepage = "https://github.com/tokio-rs/tokio"
|
||||||
description = """
|
description = """
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Timer facilities for Tokio
|
Timer facilities for Tokio
|
||||||
|
|
||||||
[Documentation](https://docs.rs/tokio-timer/0.2.11/tokio_timer/)
|
[Documentation](https://docs.rs/tokio-timer/0.2.12/tokio_timer/)
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ use timer;
|
|||||||
|
|
||||||
use tokio_executor::Enter;
|
use tokio_executor::Enter;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::RefCell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
@@ -23,13 +22,13 @@ pub struct Clock {
|
|||||||
|
|
||||||
/// A guard that resets the current `Clock` to `None` when dropped.
|
/// A guard that resets the current `Clock` to `None` when dropped.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DefaultGuard<'a> {
|
pub struct DefaultGuard {
|
||||||
_lifetime: PhantomData<&'a ()>,
|
_p: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
/// Thread-local tracking the current clock
|
/// Thread-local tracking the current clock
|
||||||
static CLOCK: Cell<Option<*const Clock>> = Cell::new(None)
|
static CLOCK: RefCell<Option<Clock>> = RefCell::new(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an `Instant` corresponding to "now".
|
/// Returns an `Instant` corresponding to "now".
|
||||||
@@ -50,8 +49,8 @@ thread_local! {
|
|||||||
/// let now = clock::now();
|
/// let now = clock::now();
|
||||||
/// ```
|
/// ```
|
||||||
pub fn now() -> Instant {
|
pub fn now() -> Instant {
|
||||||
CLOCK.with(|current| match current.get() {
|
CLOCK.with(|current| match current.borrow().as_ref() {
|
||||||
Some(ptr) => unsafe { (*ptr).now() },
|
Some(c) => c.now(),
|
||||||
None => Instant::now(),
|
None => Instant::now(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -60,8 +59,8 @@ impl Clock {
|
|||||||
/// Return a new `Clock` instance that uses the current execution context's
|
/// Return a new `Clock` instance that uses the current execution context's
|
||||||
/// source of time.
|
/// source of time.
|
||||||
pub fn new() -> Clock {
|
pub fn new() -> Clock {
|
||||||
CLOCK.with(|current| match current.get() {
|
CLOCK.with(|current| match current.borrow().as_ref() {
|
||||||
Some(ptr) => unsafe { (*ptr).clone() },
|
Some(c) => c.clone(),
|
||||||
None => Clock::system(),
|
None => Clock::system(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -131,25 +130,21 @@ where
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// This function panics if there already is a default clock set.
|
/// This function panics if there already is a default clock set.
|
||||||
pub fn set_default(clock: &Clock) -> DefaultGuard<'_> {
|
pub fn set_default(clock: &Clock) -> DefaultGuard {
|
||||||
CLOCK.with(|cell| {
|
CLOCK.with(|cell| {
|
||||||
assert!(
|
assert!(
|
||||||
cell.get().is_none(),
|
cell.borrow().is_none(),
|
||||||
"default clock already set for execution context"
|
"default clock already set for execution context"
|
||||||
);
|
);
|
||||||
|
|
||||||
cell.set(Some(clock as *const Clock));
|
*cell.borrow_mut() = Some(clock.clone());
|
||||||
|
|
||||||
DefaultGuard {
|
DefaultGuard { _p: () }
|
||||||
_lifetime: PhantomData,
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for DefaultGuard<'a> {
|
impl Drop for DefaultGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = CLOCK.try_with(|cell| {
|
let _ = CLOCK.try_with(|cell| cell.borrow_mut().take());
|
||||||
cell.set(None);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#![doc(html_root_url = "https://docs.rs/tokio-timer/0.2.11")]
|
#![doc(html_root_url = "https://docs.rs/tokio-timer/0.2.12")]
|
||||||
#![deny(missing_docs, missing_debug_implementations)]
|
#![deny(missing_docs, missing_debug_implementations)]
|
||||||
|
|
||||||
//! Utilities for tracking time.
|
//! Utilities for tracking time.
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use tokio_executor::Enter;
|
|||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
@@ -47,8 +46,8 @@ pub(crate) struct HandlePriv {
|
|||||||
|
|
||||||
/// A guard that resets the current timer to `None` when dropped.
|
/// A guard that resets the current timer to `None` when dropped.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct DefaultGuard<'a> {
|
pub struct DefaultGuard {
|
||||||
_lifetime: PhantomData<&'a ()>,
|
_p: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
@@ -80,7 +79,7 @@ where
|
|||||||
/// # Panics
|
/// # Panics
|
||||||
///
|
///
|
||||||
/// This function panics if there already is a default timer set.
|
/// This function panics if there already is a default timer set.
|
||||||
pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
|
pub fn set_default(handle: &Handle) -> DefaultGuard {
|
||||||
CURRENT_TIMER.with(|current| {
|
CURRENT_TIMER.with(|current| {
|
||||||
let mut current = current.borrow_mut();
|
let mut current = current.borrow_mut();
|
||||||
|
|
||||||
@@ -96,9 +95,7 @@ pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
|
|||||||
|
|
||||||
*current = Some(handle.clone());
|
*current = Some(handle.clone());
|
||||||
});
|
});
|
||||||
DefaultGuard {
|
DefaultGuard { _p: () }
|
||||||
_lifetime: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Handle {
|
impl Handle {
|
||||||
@@ -194,7 +191,7 @@ impl fmt::Debug for HandlePriv {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Drop for DefaultGuard<'a> {
|
impl Drop for DefaultGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let _ = CURRENT_TIMER.try_with(|current| {
|
let _ = CURRENT_TIMER.try_with(|current| {
|
||||||
let mut current = current.borrow_mut();
|
let mut current = current.borrow_mut();
|
||||||
|
|||||||
Reference in New Issue
Block a user