diff --git a/ylong_runtime/src/executor/async_pool.rs b/ylong_runtime/src/executor/async_pool.rs index a3f42d966719e62d8fcede629fc14ef1ff43b9e5..5bf03f3a54aeeab5c084e7cfc2687a9ba4a563d9 100644 --- a/ylong_runtime/src/executor/async_pool.rs +++ b/ylong_runtime/src/executor/async_pool.rs @@ -317,7 +317,7 @@ impl MultiThreadScheduler { } let num = self.locals.len(); - let start = fast_random() >> 56; + let start = (fast_random() >> 56) as usize; for i in 0..num { let i = (start + i) % num; diff --git a/ylong_runtime/src/net/async_source.rs b/ylong_runtime/src/net/async_source.rs index 910ad187c9daee77026bf677853d65333cb32b3e..831b33a573643caa9e179e89fd7cda5a49e74133 100644 --- a/ylong_runtime/src/net/async_source.rs +++ b/ylong_runtime/src/net/async_source.rs @@ -53,7 +53,7 @@ impl AsyncSource { pub fn new(mut io: E, interest: Option) -> io::Result> { #[cfg(not(feature = "ffrt"))] let inner = { - let context = get_current_ctx().ok_or(io::Error::new(io::ErrorKind::Other, "get_current_ctx() fail"))?; + let context = get_current_ctx().ok_or_else(|| io::Error::new(io::ErrorKind::Other, "get_current_ctx() fail"))?; match context { WorkerContext::Multi(ctx) => &ctx.handle, WorkerContext::Curr(ctx) => &ctx.handle, diff --git a/ylong_runtime/src/select.rs b/ylong_runtime/src/select.rs index c14c9846fc9ddafdaff2b9561f51458deaa46922..3b1c45548b57964129eca58a7d96e610ffb74b6e 100644 --- a/ylong_runtime/src/select.rs +++ b/ylong_runtime/src/select.rs @@ -200,7 +200,7 @@ macro_rules! select { // When a branch ready first, modify this variable to // branch's index to ensure that the branch is executed first. use $crate::util::fastrand::fast_random; - let mut random_number = fast_random(); + let mut random_number = fast_random() as usize; let output = { let mut futures = ( $( $fut , )+ ); diff --git a/ylong_runtime/src/util/fastrand.rs b/ylong_runtime/src/util/fastrand.rs index d66aff9c5b89acd7aa636cbfaf4b2f1dd0ebd898..8013c0398298cab8c48f02028484e75310360804 100644 --- a/ylong_runtime/src/util/fastrand.rs +++ b/ylong_runtime/src/util/fastrand.rs @@ -25,9 +25,9 @@ use std::num::Wrapping; /// ```rust /// use ylong_runtime::util::fastrand::fast_random; /// let rand = fast_random(); -/// assert!(rand <= usize::MAX); +/// assert!(rand <= u64::MAX); /// ``` -pub fn fast_random() -> usize { +pub fn fast_random() -> u64 { thread_local! { static RNG: Cell> = Cell::new(Wrapping(seed())); } @@ -39,7 +39,7 @@ pub fn fast_random() -> usize { s ^= s >> 27; rng.set(s); s.0.wrapping_mul(0x2545_f491_4f6c_dd1d) - }) as usize + }) } fn seed() -> u64 {