Merge pull request #51 from DeterminateSystems/upstream-lazy-lock
Replace lazy_static with LazyLock
This commit is contained in:
commit
13b71052e6
6 changed files with 13 additions and 28 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
|
@ -564,7 +564,6 @@ dependencies = [
|
|||
"anyhow",
|
||||
"cstr",
|
||||
"ctor",
|
||||
"lazy_static",
|
||||
"nix-bindings-bdwgc-sys",
|
||||
"nix-bindings-expr-sys",
|
||||
"nix-bindings-store",
|
||||
|
|
@ -614,7 +613,6 @@ dependencies = [
|
|||
"anyhow",
|
||||
"cstr",
|
||||
"ctor",
|
||||
"lazy_static",
|
||||
"nix-bindings-expr",
|
||||
"nix-bindings-fetchers",
|
||||
"nix-bindings-flake-sys",
|
||||
|
|
@ -644,7 +642,6 @@ dependencies = [
|
|||
"ctor",
|
||||
"harmonia-store-core",
|
||||
"hex-literal",
|
||||
"lazy_static",
|
||||
"nix-bindings-store-sys",
|
||||
"nix-bindings-util",
|
||||
"nix-bindings-util-sys",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ nix-bindings-bdwgc-sys = { path = "../nix-bindings-bdwgc-sys", version = "0.2.1"
|
|||
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
|
||||
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
|
||||
nix-bindings-expr-sys = { path = "../nix-bindings-expr-sys", version = "0.2.1" }
|
||||
lazy_static = "1.4"
|
||||
ctor = "0.2"
|
||||
tempfile = "3.10"
|
||||
cstr = "0.2"
|
||||
|
|
|
|||
|
|
@ -133,7 +133,6 @@ use crate::value::{Int, Value, ValueType};
|
|||
use anyhow::Context as _;
|
||||
use anyhow::{bail, Result};
|
||||
use cstr::cstr;
|
||||
use lazy_static::lazy_static;
|
||||
use nix_bindings_bdwgc_sys as gc;
|
||||
use nix_bindings_expr_sys as raw;
|
||||
use nix_bindings_store::path::StorePath;
|
||||
|
|
@ -148,17 +147,13 @@ use std::ffi::{c_char, CString};
|
|||
use std::iter::FromIterator;
|
||||
use std::os::raw::c_uint;
|
||||
use std::ptr::{null, null_mut, NonNull};
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::sync::{Arc, LazyLock, Weak};
|
||||
|
||||
lazy_static! {
|
||||
static ref INIT: Result<()> = {
|
||||
unsafe {
|
||||
gc::GC_allow_register_threads();
|
||||
check_call!(raw::libexpr_init(&mut Context::new()))?;
|
||||
Ok(())
|
||||
}
|
||||
};
|
||||
}
|
||||
static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
|
||||
gc::GC_allow_register_threads();
|
||||
check_call!(raw::libexpr_init(&mut Context::new()))?;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
pub fn init() -> Result<()> {
|
||||
let x = INIT.as_ref();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ nix-bindings-fetchers = { path = "../nix-bindings-fetchers", version = "0.2.1" }
|
|||
nix-bindings-store = { path = "../nix-bindings-store", version = "0.2.1" }
|
||||
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
|
||||
nix-bindings-flake-sys = { path = "../nix-bindings-flake-sys", version = "0.2.1" }
|
||||
lazy_static = "1.4"
|
||||
ctor = "0.2"
|
||||
tempfile = "3.10"
|
||||
cstr = "0.2"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ anyhow = "1.0"
|
|||
nix-bindings-util = { path = "../nix-bindings-util", version = "0.2.1" }
|
||||
nix-bindings-util-sys = { path = "../nix-bindings-util-sys", version = "0.2.1" }
|
||||
nix-bindings-store-sys = { path = "../nix-bindings-store-sys", version = "0.2.1" }
|
||||
lazy_static = "1.4"
|
||||
zerocopy = "0.8"
|
||||
harmonia-store-core = { version = "0.0.0-alpha.0", optional = true }
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use anyhow::{bail, Error, Result};
|
||||
use lazy_static::lazy_static;
|
||||
use nix_bindings_store_sys as raw;
|
||||
use nix_bindings_util::context::Context;
|
||||
use nix_bindings_util::string_return::{
|
||||
|
|
@ -13,19 +12,17 @@ use std::collections::HashMap;
|
|||
use std::ffi::{c_char, CString};
|
||||
use std::ptr::null_mut;
|
||||
use std::ptr::NonNull;
|
||||
use std::sync::{Arc, Mutex, Weak};
|
||||
use std::sync::{Arc, LazyLock, Mutex, Weak};
|
||||
|
||||
#[cfg(nix_at_least = "2.33.0pre")]
|
||||
use crate::derivation::Derivation;
|
||||
use crate::path::StorePath;
|
||||
|
||||
/* TODO make Nix itself thread safe */
|
||||
lazy_static! {
|
||||
static ref INIT: Result<()> = unsafe {
|
||||
check_call!(raw::libstore_init(&mut Context::new()))?;
|
||||
Ok(())
|
||||
};
|
||||
}
|
||||
static INIT: LazyLock<Result<()>> = LazyLock::new(|| unsafe {
|
||||
check_call!(raw::libstore_init(&mut Context::new()))?;
|
||||
Ok(())
|
||||
});
|
||||
|
||||
struct StoreRef {
|
||||
inner: NonNull<raw::Store>,
|
||||
|
|
@ -68,9 +65,8 @@ impl StoreWeak {
|
|||
/// Protects against https://github.com/NixOS/nix/issues/11979 (unless different parameters are passed, in which case it's up to luck, but you do get your own parameters as you asked for).
|
||||
type StoreCacheMap = HashMap<(Option<String>, Vec<(String, String)>), StoreWeak>;
|
||||
|
||||
lazy_static! {
|
||||
static ref STORE_CACHE: Arc<Mutex<StoreCacheMap>> = Arc::new(Mutex::new(HashMap::new()));
|
||||
}
|
||||
static STORE_CACHE: LazyLock<Arc<Mutex<StoreCacheMap>>> =
|
||||
LazyLock::new(|| Arc::new(Mutex::new(HashMap::new())));
|
||||
|
||||
#[cfg(nix_at_least = "2.33.0pre")]
|
||||
unsafe extern "C" fn callback_get_result_store_path_set(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue