Skip to content

Commit

Permalink
use once_cell::sync::Lazy replace std::sync::LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
loongs-zhang committed Jan 30, 2024
1 parent be701d3 commit c9356d2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions monoio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fxhash = "0.2"
libc = "0.2"
pin-project-lite = "0.2"
socket2 = { version = "0.5", features = ["all"] }
once_cell = "1.19.0"

bytes = { version = "1", optional = true }
flume = { version = "0.10", optional = true }
Expand Down
14 changes: 6 additions & 8 deletions monoio/src/driver/thread.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use std::{
sync::{LazyLock, Mutex},
task::Waker,
};
use std::{sync::Mutex, task::Waker};

use flume::Sender;
use fxhash::FxHashMap;
use once_cell::sync::Lazy;

use crate::driver::UnparkHandle;

static UNPARK: LazyLock<Mutex<FxHashMap<usize, UnparkHandle>>> =
LazyLock::new(|| Mutex::new(FxHashMap::default()));
static UNPARK: Lazy<Mutex<FxHashMap<usize, UnparkHandle>>> =
Lazy::new(|| Mutex::new(FxHashMap::default()));

static WAKER_SENDER: LazyLock<Mutex<FxHashMap<usize, Sender<Waker>>>> =
LazyLock::new(|| Mutex::new(FxHashMap::default()));
static WAKER_SENDER: Lazy<Mutex<FxHashMap<usize, Sender<Waker>>>> =
Lazy::new(|| Mutex::new(FxHashMap::default()));

macro_rules! lock {
($x: ident) => {
Expand Down
7 changes: 5 additions & 2 deletions monoio/src/driver/uring/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,16 @@ impl UringInner {
self.tick();
}
#[cfg(not(feature = "unstable"))]
Err(ref e) if e.raw_os_error() == Some(libc::EAGAIN) || e.raw_os_error() == Some(libc::EBUSY) => {
Err(ref e)
if e.raw_os_error() == Some(libc::EAGAIN)
|| e.raw_os_error() == Some(libc::EBUSY) =>
{
// This error is constructed with io::Error::last_os_error():
// https://github.com/tokio-rs/io-uring/blob/01c83bbce965d4aaf93ebfaa08c3aa8b7b0f5335/src/sys/mod.rs#L32
// So we can use https://doc.rust-lang.org/nightly/std/io/struct.Error.html#method.raw_os_error
// to get the raw error code.
self.tick();
},
}
e => return e.map(|_| ()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion monoio/src/net/tcp/tfo/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{cell::Cell, io, os::fd::AsRawFd};
pub(crate) static TFO_CONNECT_AVAILABLE: Cell<bool> = Cell::new(true);

#[cfg(not(feature = "unstable"))]
thread_local!{
thread_local! {
pub(crate) static TFO_CONNECT_AVAILABLE: Cell<bool> = Cell::new(true);
}

Expand Down
4 changes: 2 additions & 2 deletions monoio/src/task/waker_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub(crate) fn dummy_waker() -> Waker {
static SHOULD_POLL: Cell<bool> = Cell::new(true);

#[cfg(not(feature = "unstable"))]
thread_local!{
static SHOULD_POLL: Cell<bool> = Cell::new(true);
thread_local! {
static SHOULD_POLL: Cell<bool> = const { Cell::new(true) };
}

#[inline]
Expand Down
4 changes: 1 addition & 3 deletions monoio/src/utils/thread_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::sync::{
atomic::{AtomicUsize, Ordering::Relaxed},
};
use std::sync::atomic::{AtomicUsize, Ordering::Relaxed};

// thread id begins from 16.
// 0 is default thread
Expand Down

0 comments on commit c9356d2

Please sign in to comment.