Skip to content

Commit

Permalink
refactor: use std::sync::OnceLock instead of once_cell (#3498)
Browse files Browse the repository at this point in the history
  • Loading branch information
StackOverflowExcept1on authored Nov 19, 2023
1 parent 7e8a664 commit 1f186ef
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lazy-pages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ sp-wasm-interface = { workspace = true, features = ["std"] }
cfg-if.workspace = true
region.workspace = true
derive_more.workspace = true
once_cell.workspace = true

gear-sandbox-host.workspace = true
gear-core.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions lazy-pages/src/init_flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#[cfg(not(test))]
mod not_tests {
use crate::InitError;
use once_cell::sync::OnceCell;
use std::sync::OnceLock;

pub struct InitializationFlag(OnceCell<Result<(), InitError>>);
pub struct InitializationFlag(OnceLock<Result<(), InitError>>);

impl InitializationFlag {
pub const fn new() -> Self {
Self(OnceCell::new())
Self(OnceLock::new())
}

pub fn get_or_init(
Expand Down
5 changes: 2 additions & 3 deletions lazy-pages/src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use nix::{
libc::{c_void, siginfo_t},
sys::{signal, signal::SigHandler},
};
use once_cell::sync::OnceCell;
use std::io;
use std::{io, sync::OnceLock};

/// Signal handler which has been set before lazy-pages initialization.
/// Currently use to support wasmer signal handler.
Expand All @@ -37,7 +36,7 @@ use std::io;
/// see https://github.com/gear-tech/substrate/blob/gear-stable/client/executor/common/src/sandbox/wasmer_backend.rs
/// and https://github.com/wasmerio/wasmer/blob/e6857d116134bdc9ab6a1dabc3544cf8e6aee22b/lib/vm/src/trap/traphandlers.rs#L548
/// So, if we receive signal from unknown memory we should try to use old (wasmer) signal handler.
static mut OLD_SIG_HANDLER: OnceCell<SigHandler> = OnceCell::new();
static OLD_SIG_HANDLER: OnceLock<SigHandler> = OnceLock::new();

cfg_if! {
if #[cfg(all(target_os = "linux", target_arch = "x86_64"))] {
Expand Down
1 change: 0 additions & 1 deletion sandbox/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ sp-allocator = { workspace = true, features = ["std"] }
sp-wasm-interface = { workspace = true, features = ["std"] }
gear-sandbox-env = { workspace = true, features = ["std"] }
wasmer-cache = { workspace = true, optional = true }
once_cell.workspace = true
tempfile.workspace = true

[features]
Expand Down
4 changes: 2 additions & 2 deletions sandbox/host/src/sandbox/wasmer_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ enum CachedModuleErr {

#[cfg(feature = "wasmer-cache")]
use {
once_cell::sync::OnceCell,
sandbox_wasmer::Module,
std::sync::OnceLock,
tempfile::TempDir,
wasmer_cache::{Cache, FileSystemCache, Hash},
CachedModuleErr::*,
};

#[cfg(feature = "wasmer-cache")]
static CACHE_DIR: OnceCell<TempDir> = OnceCell::new();
static CACHE_DIR: OnceLock<TempDir> = OnceLock::new();

/// Wasmer specific context
pub struct Backend {
Expand Down
1 change: 0 additions & 1 deletion utils/node-loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ clap = { workspace = true, features = ["derive"] }
futures.workspace = true
futures-timer.workspace = true
names = "0.14.0"
once_cell.workspace = true
parking_lot.workspace = true
primitive-types = { workspace = true, features = ["scale-info"] }
rand = { workspace = true, features = ["small_rng"] }
Expand Down
10 changes: 6 additions & 4 deletions utils/node-loader/src/batch_pool/api/nonce.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use crate::utils;
use anyhow::{anyhow, Result};
use gclient::{Error as GClientError, Result as GClientResult};
use once_cell::sync::OnceCell;
use parking_lot::{Mutex, MutexGuard};
use std::{
cmp::Reverse,
collections::BinaryHeap,
sync::atomic::{AtomicU64, Ordering},
sync::{
atomic::{AtomicU64, Ordering},
OnceLock,
},
};

pub static AVAILABLE_NONCE: OnceCell<AtomicU64> = OnceCell::new();
pub static MISSED_NONCES: OnceCell<Mutex<MinHeap>> = OnceCell::new();
pub static AVAILABLE_NONCE: OnceLock<AtomicU64> = OnceLock::new();
pub static MISSED_NONCES: OnceLock<Mutex<MinHeap>> = OnceLock::new();

pub type MinHeap = BinaryHeap<Reverse<u64>>;
type MissedNoncesGuard<'a> = MutexGuard<'a, MinHeap>;
Expand Down
1 change: 1 addition & 0 deletions utils/wasm-builder/src/cargo_toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl Toolchain {
.and_then(|s| std::str::from_utf8(s).ok())
.expect("unexpected `rustup` output");

// TODO #3499: replace it with `std::sync::LazyLock` when it becomes stable
static TOOLCHAIN_CHANNEL_RE: Lazy<Regex> = Lazy::new(|| {
// This regex is borrowed from the rustup code and modified (added non-capturing groups)
let pattern = format!(
Expand Down

0 comments on commit 1f186ef

Please sign in to comment.