summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-07-06 23:48:01 -0400
committerGitHub <noreply@github.com>2021-07-06 23:48:01 -0400
commit7fc0e8ec8cd4b18ba10a04cf0ac2bee48826de3d (patch)
tree70e078538ae0f3467e8a519b918ae936587ce2d4 /extensions
parent78ac19f51f48984ea16f97a0c574fa507544b8d5 (diff)
chore: use parking_lot for synchronization primitives to align with tokio (#11289)
parking_lot is already transitively used in tokio via the "full" cargo feature
Diffstat (limited to 'extensions')
-rw-r--r--extensions/broadcast_channel/in_memory_broadcast_channel.rs6
-rw-r--r--extensions/net/ops_tls.rs9
-rw-r--r--extensions/web/blob.rs14
3 files changed, 14 insertions, 15 deletions
diff --git a/extensions/broadcast_channel/in_memory_broadcast_channel.rs b/extensions/broadcast_channel/in_memory_broadcast_channel.rs
index 34498c830..879a3dbd5 100644
--- a/extensions/broadcast_channel/in_memory_broadcast_channel.rs
+++ b/extensions/broadcast_channel/in_memory_broadcast_channel.rs
@@ -3,8 +3,8 @@
use crate::BroadcastChannel;
use async_trait::async_trait;
use deno_core::error::AnyError;
+use deno_core::parking_lot::Mutex;
use std::sync::Arc;
-use std::sync::Mutex;
use tokio::sync::broadcast;
use tokio::sync::mpsc;
use uuid::Uuid;
@@ -41,7 +41,7 @@ impl BroadcastChannel for InMemoryBroadcastChannel {
fn subscribe(&self) -> Result<Self::Resource, AnyError> {
let (cancel_tx, cancel_rx) = mpsc::unbounded_channel();
- let broadcast_rx = self.0.lock().unwrap().subscribe();
+ let broadcast_rx = self.0.lock().subscribe();
let rx = tokio::sync::Mutex::new((broadcast_rx, cancel_rx));
let uuid = Uuid::new_v4();
Ok(Self::Resource {
@@ -64,7 +64,7 @@ impl BroadcastChannel for InMemoryBroadcastChannel {
let name = Arc::new(name);
let data = Arc::new(data);
let uuid = resource.uuid;
- self.0.lock().unwrap().send(Message { name, data, uuid })?;
+ self.0.lock().send(Message { name, data, uuid })?;
Ok(())
}
diff --git a/extensions/net/ops_tls.rs b/extensions/net/ops_tls.rs
index 701c5d1a1..092c74a69 100644
--- a/extensions/net/ops_tls.rs
+++ b/extensions/net/ops_tls.rs
@@ -28,6 +28,7 @@ use deno_core::futures::task::RawWakerVTable;
use deno_core::futures::task::Waker;
use deno_core::op_async;
use deno_core::op_sync;
+use deno_core::parking_lot::Mutex;
use deno_core::AsyncRefCell;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
@@ -66,7 +67,6 @@ use std::path::Path;
use std::pin::Pin;
use std::rc::Rc;
use std::sync::Arc;
-use std::sync::Mutex;
use std::sync::Weak;
use tokio::io::AsyncRead;
use tokio::io::AsyncWrite;
@@ -86,11 +86,11 @@ struct ClientSessionMemoryCache(Mutex<HashMap<Vec<u8>, Vec<u8>>>);
impl StoresClientSessions for ClientSessionMemoryCache {
fn get(&self, key: &[u8]) -> Option<Vec<u8>> {
- self.0.lock().unwrap().get(key).cloned()
+ self.0.lock().get(key).cloned()
}
fn put(&self, key: Vec<u8>, value: Vec<u8>) -> bool {
- let mut sessions = self.0.lock().unwrap();
+ let mut sessions = self.0.lock();
// TODO(bnoordhuis) Evict sessions LRU-style instead of arbitrarily.
while sessions.len() >= 1024 {
let key = sessions.keys().next().unwrap().clone();
@@ -511,7 +511,6 @@ impl ReadHalf {
.unwrap_or_else(|_| panic!("Arc::<Shared>::try_unwrap() failed"))
.tls_stream
.into_inner()
- .unwrap()
}
}
@@ -597,7 +596,7 @@ impl Shared {
let shared_waker = self.new_shared_waker();
let mut cx = Context::from_waker(&shared_waker);
- let mut tls_stream = self.tls_stream.lock().unwrap();
+ let mut tls_stream = self.tls_stream.lock();
f(Pin::new(&mut tls_stream), &mut cx)
}
diff --git a/extensions/web/blob.rs b/extensions/web/blob.rs
index 96a982677..bd5284317 100644
--- a/extensions/web/blob.rs
+++ b/extensions/web/blob.rs
@@ -1,5 +1,6 @@
use async_trait::async_trait;
use deno_core::error::type_error;
+use deno_core::parking_lot::Mutex;
use deno_core::url::Url;
use deno_core::ZeroCopyBuf;
use serde::Deserialize;
@@ -8,7 +9,6 @@ use std::collections::HashMap;
use std::fmt::Debug;
use std::rc::Rc;
use std::sync::Arc;
-use std::sync::Mutex;
use deno_core::error::AnyError;
use uuid::Uuid;
@@ -26,7 +26,7 @@ pub struct BlobStore {
impl BlobStore {
pub fn insert_part(&self, part: Box<dyn BlobPart + Send + Sync>) -> Uuid {
let id = Uuid::new_v4();
- let mut parts = self.parts.lock().unwrap();
+ let mut parts = self.parts.lock();
parts.insert(id, Arc::new(part));
id
}
@@ -35,7 +35,7 @@ impl BlobStore {
&self,
id: &Uuid,
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
- let parts = self.parts.lock().unwrap();
+ let parts = self.parts.lock();
let part = parts.get(&id);
part.cloned()
}
@@ -44,7 +44,7 @@ impl BlobStore {
&self,
id: &Uuid,
) -> Option<Arc<Box<dyn BlobPart + Send + Sync>>> {
- let mut parts = self.parts.lock().unwrap();
+ let mut parts = self.parts.lock();
parts.remove(&id)
}
@@ -52,7 +52,7 @@ impl BlobStore {
&self,
mut url: Url,
) -> Result<Option<Arc<Blob>>, AnyError> {
- let blob_store = self.object_urls.lock().unwrap();
+ let blob_store = self.object_urls.lock();
url.set_fragment(None);
Ok(blob_store.get(&url).cloned())
}
@@ -70,14 +70,14 @@ impl BlobStore {
let id = Uuid::new_v4();
let url = Url::parse(&format!("blob:{}/{}", origin, id)).unwrap();
- let mut blob_store = self.object_urls.lock().unwrap();
+ let mut blob_store = self.object_urls.lock();
blob_store.insert(url.clone(), Arc::new(blob));
url
}
pub fn remove_object_url(&self, url: &Url) {
- let mut blob_store = self.object_urls.lock().unwrap();
+ let mut blob_store = self.object_urls.lock();
blob_store.remove(&url);
}
}