Skip to content

Commit c9356d2

Browse files
committed
use once_cell::sync::Lazy replace std::sync::LazyLock
1 parent be701d3 commit c9356d2

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

monoio/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ fxhash = "0.2"
1919
libc = "0.2"
2020
pin-project-lite = "0.2"
2121
socket2 = { version = "0.5", features = ["all"] }
22+
once_cell = "1.19.0"
2223

2324
bytes = { version = "1", optional = true }
2425
flume = { version = "0.10", optional = true }

monoio/src/driver/thread.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
use std::{
2-
sync::{LazyLock, Mutex},
3-
task::Waker,
4-
};
1+
use std::{sync::Mutex, task::Waker};
52

63
use flume::Sender;
74
use fxhash::FxHashMap;
5+
use once_cell::sync::Lazy;
86

97
use crate::driver::UnparkHandle;
108

11-
static UNPARK: LazyLock<Mutex<FxHashMap<usize, UnparkHandle>>> =
12-
LazyLock::new(|| Mutex::new(FxHashMap::default()));
9+
static UNPARK: Lazy<Mutex<FxHashMap<usize, UnparkHandle>>> =
10+
Lazy::new(|| Mutex::new(FxHashMap::default()));
1311

14-
static WAKER_SENDER: LazyLock<Mutex<FxHashMap<usize, Sender<Waker>>>> =
15-
LazyLock::new(|| Mutex::new(FxHashMap::default()));
12+
static WAKER_SENDER: Lazy<Mutex<FxHashMap<usize, Sender<Waker>>>> =
13+
Lazy::new(|| Mutex::new(FxHashMap::default()));
1614

1715
macro_rules! lock {
1816
($x: ident) => {

monoio/src/driver/uring/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,16 @@ impl UringInner {
338338
self.tick();
339339
}
340340
#[cfg(not(feature = "unstable"))]
341-
Err(ref e) if e.raw_os_error() == Some(libc::EAGAIN) || e.raw_os_error() == Some(libc::EBUSY) => {
341+
Err(ref e)
342+
if e.raw_os_error() == Some(libc::EAGAIN)
343+
|| e.raw_os_error() == Some(libc::EBUSY) =>
344+
{
342345
// This error is constructed with io::Error::last_os_error():
343346
// https://github.com/tokio-rs/io-uring/blob/01c83bbce965d4aaf93ebfaa08c3aa8b7b0f5335/src/sys/mod.rs#L32
344347
// So we can use https://doc.rust-lang.org/nightly/std/io/struct.Error.html#method.raw_os_error
345348
// to get the raw error code.
346349
self.tick();
347-
},
350+
}
348351
e => return e.map(|_| ()),
349352
}
350353
}

monoio/src/net/tcp/tfo/linux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{cell::Cell, io, os::fd::AsRawFd};
55
pub(crate) static TFO_CONNECT_AVAILABLE: Cell<bool> = Cell::new(true);
66

77
#[cfg(not(feature = "unstable"))]
8-
thread_local!{
8+
thread_local! {
99
pub(crate) static TFO_CONNECT_AVAILABLE: Cell<bool> = Cell::new(true);
1010
}
1111

monoio/src/task/waker_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub(crate) fn dummy_waker() -> Waker {
3232
static SHOULD_POLL: Cell<bool> = Cell::new(true);
3333

3434
#[cfg(not(feature = "unstable"))]
35-
thread_local!{
36-
static SHOULD_POLL: Cell<bool> = Cell::new(true);
35+
thread_local! {
36+
static SHOULD_POLL: Cell<bool> = const { Cell::new(true) };
3737
}
3838

3939
#[inline]

monoio/src/utils/thread_id.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::sync::{
2-
atomic::{AtomicUsize, Ordering::Relaxed},
3-
};
1+
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};
42

53
// thread id begins from 16.
64
// 0 is default thread

0 commit comments

Comments
 (0)