Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use once_cell::sync::Lazy replace std::sync::LazyLock #230

Merged
merged 2 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
ihciah marked this conversation as resolved.
Show resolved Hide resolved

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
4 changes: 2 additions & 2 deletions monoio/src/net/tcp/tfo/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ 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!{
pub(crate) static TFO_CONNECT_AVAILABLE: Cell<bool> = Cell::new(true);
thread_local! {
pub(crate) static TFO_CONNECT_AVAILABLE: Cell<bool> = const { Cell::new(true) };
}

/// Call before listen.
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
Loading