Skip to content

Commit 8ce497c

Browse files
committed
change from mutex to rwlock
1 parent d929b6e commit 8ce497c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rust_i18n::t;
1818
use semver::{Version, VersionReq};
1919
use schemars::JsonSchema;
2020
use serde::{Deserialize, Serialize};
21-
use std::{collections::{BTreeMap, HashMap, HashSet}, sync::{LazyLock, Mutex}};
21+
use std::{collections::{BTreeMap, HashMap, HashSet}, sync::{LazyLock, RwLock}};
2222
use std::env;
2323
use std::ffi::OsStr;
2424
use std::fs;
@@ -34,10 +34,10 @@ const DSC_RESOURCE_EXTENSIONS: [&str; 3] = [".dsc.resource.json", ".dsc.resource
3434
const DSC_EXTENSION_EXTENSIONS: [&str; 3] = [".dsc.extension.json", ".dsc.extension.yaml", ".dsc.extension.yml"];
3535

3636
// use BTreeMap so that the results are sorted by the typename, the Vec is sorted by version
37-
static ADAPTERS: LazyLock<Mutex<BTreeMap<String, Vec<DscResource>>>> = LazyLock::new(|| Mutex::new(BTreeMap::new()));
38-
static RESOURCES: LazyLock<Mutex<BTreeMap<String, Vec<DscResource>>>> = LazyLock::new(|| Mutex::new(BTreeMap::new()));
39-
static EXTENSIONS: LazyLock<Mutex<BTreeMap<String, DscExtension>>> = LazyLock::new(|| Mutex::new(BTreeMap::new()));
40-
static ADAPTED_RESOURCES: LazyLock<Mutex<BTreeMap<String, Vec<DscResource>>>> = LazyLock::new(|| Mutex::new(BTreeMap::new()));
37+
static ADAPTERS: LazyLock<RwLock<BTreeMap<String, Vec<DscResource>>>> = LazyLock::new(|| RwLock::new(BTreeMap::new()));
38+
static RESOURCES: LazyLock<RwLock<BTreeMap<String, Vec<DscResource>>>> = LazyLock::new(|| RwLock::new(BTreeMap::new()));
39+
static EXTENSIONS: LazyLock<RwLock<BTreeMap<String, DscExtension>>> = LazyLock::new(|| RwLock::new(BTreeMap::new()));
40+
static ADAPTED_RESOURCES: LazyLock<RwLock<BTreeMap<String, Vec<DscResource>>>> = LazyLock::new(|| RwLock::new(BTreeMap::new()));
4141

4242
#[derive(Clone, Serialize, Deserialize, JsonSchema)]
4343
pub enum ImportedManifest {

dsc_lib/src/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,28 @@ fn get_settings_policy_file_path() -> String
216216
#[macro_export]
217217
macro_rules! locked_is_empty {
218218
($lockable:expr) => {{
219-
$lockable.lock().unwrap().is_empty()
219+
$lockable.read().unwrap().is_empty()
220220
}};
221221
}
222222

223223
#[macro_export]
224224
macro_rules! locked_extend {
225225
($lockable:expr, $items:expr) => {{
226-
$lockable.lock().unwrap().extend($items);
226+
$lockable.write().unwrap().extend($items);
227227
}};
228228
}
229229

230230
#[macro_export]
231231
macro_rules! locked_clone {
232232
($lockable:expr) => {{
233-
$lockable.lock().unwrap().clone()
233+
$lockable.read().unwrap().clone()
234234
}};
235235
}
236236

237237
#[macro_export]
238238
macro_rules! locked_get {
239239
($lockable:expr, $key:expr) => {{
240-
if let Some(v) = $lockable.lock().unwrap().get($key) {
240+
if let Some(v) = $lockable.read().unwrap().get($key) {
241241
Some(v.clone())
242242
} else {
243243
None

0 commit comments

Comments
 (0)