From 2ea3e0c5f0dc24a5395579894cc8a55bc6aa8cd5 Mon Sep 17 00:00:00 2001 From: misssonder <819643718@qq.com> Date: Tue, 14 May 2024 19:25:32 +0800 Subject: [PATCH] Fix can't compile features not_std and sync --- Cargo.toml | 2 +- src/func/native.rs | 30 ++---------------------------- src/types/dynamic.rs | 2 +- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 642382a13..28afb6a0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ bitflags = { version = "2.0.0", default-features = false } smartstring = { version = "1.0.0", default-features = false } rhai_codegen = { version = "2.1.0", path = "codegen" } -no-std-compat = { git = "https://gitlab.com/jD91mZM2/no-std-compat", version = "0.4.1", default-features = false, features = ["alloc"], optional = true } +no-std-compat = { git = "https://gitlab.com/jD91mZM2/no-std-compat", version = "0.4.1", default-features = false, features = ["alloc", "compat_sync"], optional = true } libm = { version = "0.2.0", default-features = false, optional = true } hashbrown = { version = "0.14.0", optional = true } core-error = { version = "0.0.0", default-features = false, features = ["alloc"], optional = true } diff --git a/src/func/native.rs b/src/func/native.rs index 94f128067..446f71d26 100644 --- a/src/func/native.rs +++ b/src/func/native.rs @@ -534,20 +534,7 @@ pub fn locked_read(value: &Locked) -> Option> { #[cfg(feature = "sync")] #[cfg(not(feature = "unchecked"))] - { - // Spin-lock for a short while before giving up - for _ in 0..10 { - match value.try_read() { - Ok(guard) => return Some(guard), - Err(std::sync::TryLockError::WouldBlock) => { - std::thread::sleep(std::time::Duration::from_secs(1)) - } - Err(_) => return None, - } - } - - return None; - } + return value.try_read(); } /// _(internals)_ Lock a [`Locked`] resource for mutable access. @@ -565,20 +552,7 @@ pub fn locked_write(value: &Locked) -> Option> { #[cfg(feature = "sync")] #[cfg(not(feature = "unchecked"))] - { - // Spin-lock for a short while before giving up - for _ in 0..10 { - match value.try_write() { - Ok(guard) => return Some(guard), - Err(std::sync::TryLockError::WouldBlock) => { - std::thread::sleep(std::time::Duration::from_secs(1)) - } - Err(_) => return None, - } - } - - return None; - } + return value.try_write(); } /// General Rust function trail object. diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index 52097a380..b54410adb 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -1701,7 +1701,7 @@ impl Dynamic { #[cfg(not(feature = "sync"))] Ok(value) => value.into_inner().flatten(), #[cfg(feature = "sync")] - Ok(value) => value.into_inner().unwrap().flatten(), + Ok(value) => value.into_inner().flatten(), // If there are outstanding references, return a cloned copy Err(cell) => { if let Some(guard) = crate::func::locked_read(&cell) {