Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace std::sync locks with parking_lot locks #9731

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/node-bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ serde_json = "1.0.116"
toml = "0.8.12"
anyhow = "1.0.82"
mockall = "0.12.1"
parking_lot = "0.12"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
sentry = { version = "0.32.2", optional = true, default-features = false, features = ["backtrace", "contexts", "panic", "reqwest", "debug-images", "anyhow"]}
Expand Down
8 changes: 4 additions & 4 deletions crates/node-bindings/src/init_sentry/sentry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use parking_lot::Mutex;
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;

use napi::Error;
Expand Down Expand Up @@ -33,7 +33,7 @@ fn init_sentry() -> Result<(), Status> {

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

if SENTRY_GUARD.lock().unwrap().is_some() {
if SENTRY_GUARD.lock().is_some() {
return Err(Error::from_reason(
"Sentry guard already set, should only initialise Sentry once.",
));
Expand Down Expand Up @@ -75,7 +75,7 @@ fn init_sentry() -> Result<(), Status> {

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

SENTRY_GUARD.lock().unwrap().replace(guard);
SENTRY_GUARD.lock().replace(guard);

sentry::configure_scope(|scope| {
scope.set_user(Some(sentry::User {
Expand All @@ -93,7 +93,7 @@ fn init_sentry() -> Result<(), Status> {

#[napi]
fn close_sentry() {
if let Some(guard) = SENTRY_GUARD.lock().unwrap().take() {
if let Some(guard) = SENTRY_GUARD.lock().take() {
guard.close(Some(TIMEOUT));
}
}
1 change: 1 addition & 0 deletions packages/transformers/js/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ pathdiff = "0.2.0"
path-slash = "0.1.4"
indexmap = "1.9.2"
parcel-macros = { path = "../../../../crates/macros" }
parking_lot = "0.12"
8 changes: 5 additions & 3 deletions packages/transformers/js/core/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,19 +409,21 @@ macro_rules! id {
}

#[derive(Debug, Clone, Default)]
pub struct ErrorBuffer(std::sync::Arc<std::sync::Mutex<Vec<swc_core::common::errors::Diagnostic>>>);
pub struct ErrorBuffer(
std::sync::Arc<parking_lot::Mutex<Vec<swc_core::common::errors::Diagnostic>>>,
);

impl Emitter for ErrorBuffer {
fn emit(&mut self, db: &DiagnosticBuilder) {
self.0.lock().unwrap().push((**db).clone());
self.0.lock().push((**db).clone());
}
}

pub fn error_buffer_to_diagnostics(
error_buffer: &ErrorBuffer,
source_map: &SourceMap,
) -> Vec<Diagnostic> {
let s = error_buffer.0.lock().unwrap().clone();
let s = error_buffer.0.lock().clone();
s.iter()
.map(|diagnostic| {
let message = diagnostic.message();
Expand Down
1 change: 1 addition & 0 deletions packages/utils/node-resolver-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ elsa = "1.7.0"
once_cell = "1.17.0"
glob-match = "0.2.1"
dashmap = "5.4.0"
parking_lot = "0.12"

[dev-dependencies]
assert_fs = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/node-resolver-rs/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::borrow::Cow;
use std::ops::Deref;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Mutex;

use dashmap::DashMap;
use elsa::sync::FrozenMap;
use parcel_filesystem::FileSystem;
use parking_lot::Mutex;
use typed_arena::Arena;

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