Skip to content

Commit 2125d8f

Browse files
committed
Replace std::sync locks with parking_lot locks
1 parent c3505e5 commit 2125d8f

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/node-bindings/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ serde_json = "1.0.116"
3030
toml = "0.8.12"
3131
anyhow = "1.0.82"
3232
mockall = "0.12.1"
33+
parking_lot = "0.12"
3334

3435
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3536
sentry = { version = "0.32.2", optional = true, default-features = false, features = ["backtrace", "contexts", "panic", "reqwest", "debug-images", "anyhow"]}

crates/node-bindings/src/init_sentry/sentry.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use parking_lot::Mutex;
12
use std::collections::HashMap;
23
use std::sync::Arc;
3-
use std::sync::Mutex;
44
use std::time::Duration;
55

66
use napi::Error;
@@ -26,7 +26,7 @@ fn init_sentry() -> Result<(), Status> {
2626

2727
log::info!("Initialising Sentry in rust...");
2828

29-
if SENTRY_GUARD.lock().unwrap().is_some() {
29+
if SENTRY_GUARD.lock().is_some() {
3030
return Err(Error::from_reason(
3131
"Sentry guard already set, should only initialise Sentry once.",
3232
));
@@ -63,7 +63,7 @@ fn init_sentry() -> Result<(), Status> {
6363

6464
let guard = init((sentry_dsn, sentry_client_options));
6565

66-
SENTRY_GUARD.lock().unwrap().replace(guard);
66+
SENTRY_GUARD.lock().replace(guard);
6767

6868
sentry::configure_scope(|scope| {
6969
scope.set_user(Some(sentry::User {
@@ -81,7 +81,7 @@ fn init_sentry() -> Result<(), Status> {
8181

8282
#[napi]
8383
fn close_sentry() {
84-
if let Some(guard) = SENTRY_GUARD.lock().unwrap().take() {
84+
if let Some(guard) = SENTRY_GUARD.lock().take() {
8585
guard.close(Some(TIMEOUT));
8686
}
8787
}

packages/transformers/js/core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ pathdiff = "0.2.0"
3737
path-slash = "0.1.4"
3838
indexmap = "1.9.2"
3939
parcel-macros = { path = "../../../../crates/macros" }
40+
parking_lot = "0.12"

packages/transformers/js/core/src/utils.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -409,19 +409,21 @@ macro_rules! id {
409409
}
410410

411411
#[derive(Debug, Clone, Default)]
412-
pub struct ErrorBuffer(std::sync::Arc<std::sync::Mutex<Vec<swc_core::common::errors::Diagnostic>>>);
412+
pub struct ErrorBuffer(
413+
std::sync::Arc<parking_lot::Mutex<Vec<swc_core::common::errors::Diagnostic>>>,
414+
);
413415

414416
impl Emitter for ErrorBuffer {
415417
fn emit(&mut self, db: &DiagnosticBuilder) {
416-
self.0.lock().unwrap().push((**db).clone());
418+
self.0.lock().push((**db).clone());
417419
}
418420
}
419421

420422
pub fn error_buffer_to_diagnostics(
421423
error_buffer: &ErrorBuffer,
422424
source_map: &SourceMap,
423425
) -> Vec<Diagnostic> {
424-
let s = error_buffer.0.lock().unwrap().clone();
426+
let s = error_buffer.0.lock().clone();
425427
s.iter()
426428
.map(|diagnostic| {
427429
let message = diagnostic.message();

packages/utils/node-resolver-rs/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ elsa = "1.7.0"
2020
once_cell = "1.17.0"
2121
glob-match = "0.2.1"
2222
dashmap = "5.4.0"
23+
parking_lot = "0.12"
2324

2425
[dev-dependencies]
2526
assert_fs = "1.0"

packages/utils/node-resolver-rs/src/cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use std::borrow::Cow;
22
use std::ops::Deref;
33
use std::path::Path;
44
use std::path::PathBuf;
5-
use std::sync::Mutex;
65

76
use dashmap::DashMap;
87
use elsa::sync::FrozenMap;
98
use parcel_filesystem::FileSystem;
9+
use parking_lot::Mutex;
1010
use typed_arena::Arena;
1111

1212
use crate::package_json::PackageJson;
@@ -193,7 +193,7 @@ fn read<F: FileSystem>(
193193
arena: &Mutex<Arena<Box<str>>>,
194194
path: &Path,
195195
) -> std::io::Result<&'static mut str> {
196-
let arena = arena.lock().unwrap();
196+
let arena = arena.lock();
197197
let data = arena.alloc(fs.read_to_string(path)?.into_boxed_str());
198198
// The data lives as long as the arena. In public methods, we only vend temporary references.
199199
Ok(unsafe { &mut *(&mut **data as *mut str) })

0 commit comments

Comments
 (0)