From f08fcd0bbb0be46079df989d2210ad5d83967eca Mon Sep 17 00:00:00 2001 From: k-nasa Date: Tue, 1 Oct 2019 17:43:31 +0900 Subject: [PATCH] refactor --- src/sync/mutex.rs | 2 +- src/sync/rwlock.rs | 2 +- src/task/block_on.rs | 3 +-- src/task/blocking.rs | 4 ++-- src/task/builder.rs | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/sync/mutex.rs b/src/sync/mutex.rs index 8ae51ad..673eb83 100644 --- a/src/sync/mutex.rs +++ b/src/sync/mutex.rs @@ -10,7 +10,7 @@ use crate::future::Future; use crate::task::{Context, Poll, Waker}; /// Set if the mutex is locked. -const LOCK: usize = 1 << 0; +const LOCK: usize = 1; /// Set if there are tasks blocked on the mutex. const BLOCKED: usize = 1 << 1; diff --git a/src/sync/rwlock.rs b/src/sync/rwlock.rs index 36f475b..55a29fc 100644 --- a/src/sync/rwlock.rs +++ b/src/sync/rwlock.rs @@ -10,7 +10,7 @@ use crate::future::Future; use crate::task::{Context, Poll, Waker}; /// Set if a write lock is held. -const WRITE_LOCK: usize = 1 << 0; +const WRITE_LOCK: usize = 1; /// Set if there are read operations blocked on the lock. const BLOCKED_READS: usize = 1 << 1; diff --git a/src/task/block_on.rs b/src/task/block_on.rs index 2d49dca..f585693 100644 --- a/src/task/block_on.rs +++ b/src/task/block_on.rs @@ -69,12 +69,11 @@ where let future = task_local::add_finalizer(future); let future = async move { - let res = future.await; + future.await; trace!("block_on completed", { parent_id: parent_id, child_id: child_id, }); - res }; // Pin the future onto the stack. diff --git a/src/task/blocking.rs b/src/task/blocking.rs index 41177bc..8f4277c 100644 --- a/src/task/blocking.rs +++ b/src/task/blocking.rs @@ -135,7 +135,7 @@ fn random(n: u32) -> u32 { use std::num::Wrapping; thread_local! { - static RNG: Cell> = Cell::new(Wrapping(1406868647)); + static RNG: Cell> = Cell::new(Wrapping(1_406_868_647)); } RNG.with(|rng| { @@ -152,6 +152,6 @@ fn random(n: u32) -> u32 { // // Author: Daniel Lemire // Source: https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/ - ((x.0 as u64).wrapping_mul(n as u64) >> 32) as u32 + ((u64::from(x.0)).wrapping_mul(u64::from(n)) >> 32) as u32 }) } diff --git a/src/task/builder.rs b/src/task/builder.rs index 630876c..a43b42b 100644 --- a/src/task/builder.rs +++ b/src/task/builder.rs @@ -4,7 +4,7 @@ use crate::future::Future; use crate::io; /// Task builder that configures the settings of a new task. -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Builder { pub(crate) name: Option, }