Skip to content

Commit

Permalink
replace Mutex with parking_lot
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed May 29, 2023
1 parent b7fdc36 commit cddf10d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 0.10
# 0.10.1

* replaced Mutex with DebugMutex and thus with parking_lot

# 0.10.0

* removed Js*Adapter/Facade traits
* renamed JSValueRef to QuickjsValueAdapter
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickjs_runtime"
version = "0.10.0"
version = "0.10.1"
authors = ["Andries Hiemstra <info@hirofa.com>"]
edition = "2018"
description = "Wrapper API and utils for the QuickJS JavaScript engine with support for Promise, Modules, Async/await"
Expand Down
4 changes: 2 additions & 2 deletions src/jsutils/promises.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where
err.get_message(),
err.get_stack(),
)
.expect("could not create str");
.expect("could not create error");
prom_ref
.js_promise_reject(realm, &err_ref)
.expect("prom rejection failed");
Expand All @@ -77,7 +77,7 @@ where
err.get_message(),
err.get_stack(),
)
.expect("could not create str");
.expect("could not create error");
prom_ref
.js_promise_reject(realm, &err_ref)
.expect("prom rejection failed");
Expand Down
2 changes: 1 addition & 1 deletion src/quickjsrealmadapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ impl QuickJsRealmAdapter {
Ok(obj)
}
JsValueFacade::Promise { producer } => {
let producer = &mut *producer.lock().unwrap();
let producer = &mut *producer.lock("from_js_value_facade").unwrap();
if producer.is_some() {
self.create_resolving_promise_async(producer.take().unwrap(), |realm, jsvf| {
realm.from_js_value_facade(jsvf)
Expand Down
16 changes: 10 additions & 6 deletions src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ use crate::quickjsvalueadapter::QuickJsValueAdapter;
use crate::reflection::JsProxyInstanceId;
use futures::executor::block_on;
use futures::Future;
use hirofa_utils::debug_mutex::DebugMutex;
use hirofa_utils::resolvable_future::ResolvableFuture;
use serde::Serialize;
use serde_json::Value;
use std::collections::HashMap;
use std::error::Error;
use std::fmt::{Debug, Formatter};
use std::pin::Pin;
use std::sync::{Arc, Mutex, Weak};
use std::sync::{Arc, Weak};
use string_cache::DefaultAtom;

pub struct CachedJsObjectRef {
pub(crate) id: i32,
rti: Weak<QuickjsRuntimeFacadeInner>,
realm_id: String,
drop_action: Mutex<Option<Box<dyn FnOnce() + Send>>>,
drop_action: DebugMutex<Option<Box<dyn FnOnce() + Send>>>,
}

pub struct CachedJsPromiseRef {
Expand Down Expand Up @@ -67,7 +68,10 @@ impl CachedJsObjectRef {
id,
rti,
realm_id: realm_name,
drop_action: Mutex::new(Some(Box::new(drop_action))),
drop_action: DebugMutex::new(
Some(Box::new(drop_action)),
"CachedJsObjectRef.drop_action",
),
}
}
pub async fn to_json_string(&self) -> Result<String, JsError> {
Expand Down Expand Up @@ -184,7 +188,7 @@ impl CachedJsObjectRef {

impl Drop for CachedJsObjectRef {
fn drop(&mut self) {
let lck = &mut *self.drop_action.lock().unwrap();
let lck = &mut *self.drop_action.lock("drop").unwrap();
if let Some(da) = lck.take() {
da();
}
Expand Down Expand Up @@ -376,7 +380,7 @@ pub enum JsValueFacade {
},
// promise created from rust which will run an async producer
Promise {
producer: Mutex<
producer: DebugMutex<
Option<Pin<Box<dyn Future<Output = Result<JsValueFacade, JsError>> + Send + 'static>>>,
>,
},
Expand Down Expand Up @@ -466,7 +470,7 @@ impl JsValueFacade {
P: Future<Output = Result<JsValueFacade, JsError>> + Send + 'static,
{
JsValueFacade::Promise {
producer: Mutex::new(Some(Box::pin(producer))),
producer: DebugMutex::new(Some(Box::pin(producer)), "JsValueFacade::Promise.producer"),
}
}

Expand Down

0 comments on commit cddf10d

Please sign in to comment.