mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-01 00:00:10 +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,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)
|
||||
|
||||
### Added
|
||||
|
||||
@@ -8,11 +8,11 @@ name = "tokio-timer"
|
||||
# - README.md
|
||||
# - Update CHANGELOG.md.
|
||||
# - Create "v0.2.x" git tag.
|
||||
version = "0.2.11"
|
||||
version = "0.2.12"
|
||||
authors = ["Carl Lerche <[email protected]>"]
|
||||
license = "MIT"
|
||||
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"
|
||||
homepage = "https://github.com/tokio-rs/tokio"
|
||||
description = """
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -3,9 +3,8 @@ use timer;
|
||||
|
||||
use tokio_executor::Enter;
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -23,13 +22,13 @@ pub struct Clock {
|
||||
|
||||
/// A guard that resets the current `Clock` to `None` when dropped.
|
||||
#[derive(Debug)]
|
||||
pub struct DefaultGuard<'a> {
|
||||
_lifetime: PhantomData<&'a ()>,
|
||||
pub struct DefaultGuard {
|
||||
_p: (),
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
/// 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".
|
||||
@@ -50,8 +49,8 @@ thread_local! {
|
||||
/// let now = clock::now();
|
||||
/// ```
|
||||
pub fn now() -> Instant {
|
||||
CLOCK.with(|current| match current.get() {
|
||||
Some(ptr) => unsafe { (*ptr).now() },
|
||||
CLOCK.with(|current| match current.borrow().as_ref() {
|
||||
Some(c) => c.now(),
|
||||
None => Instant::now(),
|
||||
})
|
||||
}
|
||||
@@ -60,8 +59,8 @@ impl Clock {
|
||||
/// Return a new `Clock` instance that uses the current execution context's
|
||||
/// source of time.
|
||||
pub fn new() -> Clock {
|
||||
CLOCK.with(|current| match current.get() {
|
||||
Some(ptr) => unsafe { (*ptr).clone() },
|
||||
CLOCK.with(|current| match current.borrow().as_ref() {
|
||||
Some(c) => c.clone(),
|
||||
None => Clock::system(),
|
||||
})
|
||||
}
|
||||
@@ -131,25 +130,21 @@ where
|
||||
/// # Panics
|
||||
///
|
||||
/// 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| {
|
||||
assert!(
|
||||
cell.get().is_none(),
|
||||
cell.borrow().is_none(),
|
||||
"default clock already set for execution context"
|
||||
);
|
||||
|
||||
cell.set(Some(clock as *const Clock));
|
||||
*cell.borrow_mut() = Some(clock.clone());
|
||||
|
||||
DefaultGuard {
|
||||
_lifetime: PhantomData,
|
||||
}
|
||||
DefaultGuard { _p: () }
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> Drop for DefaultGuard<'a> {
|
||||
impl Drop for DefaultGuard {
|
||||
fn drop(&mut self) {
|
||||
let _ = CLOCK.try_with(|cell| {
|
||||
cell.set(None);
|
||||
});
|
||||
let _ = CLOCK.try_with(|cell| cell.borrow_mut().take());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)]
|
||||
|
||||
//! Utilities for tracking time.
|
||||
|
||||
@@ -5,7 +5,6 @@ use tokio_executor::Enter;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -47,8 +46,8 @@ pub(crate) struct HandlePriv {
|
||||
|
||||
/// A guard that resets the current timer to `None` when dropped.
|
||||
#[derive(Debug)]
|
||||
pub struct DefaultGuard<'a> {
|
||||
_lifetime: PhantomData<&'a ()>,
|
||||
pub struct DefaultGuard {
|
||||
_p: (),
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
@@ -80,7 +79,7 @@ where
|
||||
/// # Panics
|
||||
///
|
||||
/// 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| {
|
||||
let mut current = current.borrow_mut();
|
||||
|
||||
@@ -96,9 +95,7 @@ pub fn set_default(handle: &Handle) -> DefaultGuard<'_> {
|
||||
|
||||
*current = Some(handle.clone());
|
||||
});
|
||||
DefaultGuard {
|
||||
_lifetime: PhantomData,
|
||||
}
|
||||
DefaultGuard { _p: () }
|
||||
}
|
||||
|
||||
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) {
|
||||
let _ = CURRENT_TIMER.try_with(|current| {
|
||||
let mut current = current.borrow_mut();
|
||||
|
||||
Reference in New Issue
Block a user