Skip to content

Commit

Permalink
deps: update deps and switch to parking_lot (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
giangndm authored Oct 4, 2024
1 parent e19bda9 commit 5dd3b5a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tracing-subscriber = "0.3"
atm0s-sdn = "0.2"
serde = "1.0"
bincode = "1.3"
metrics-dashboard = "0.2"
metrics-dashboard = "0.3"
poem = "2.0"
metrics = "0.22"
quinn = "0.11"
Expand All @@ -32,6 +32,8 @@ local-ip-address = "0.6"
derive_more = "1.0"
thiserror = "1.0"
anyhow = "1.0"
parking_lot = "0.12"
futures = "0.3"

[profile.release]
strip = true # Automatically strip symbols from the binary.
Expand Down
3 changes: 2 additions & 1 deletion crates/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ derive_more = { workspace = true, features = ["from"] }
rand = { workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }
futures = { version = "0.3" }
futures = { workspace = true }
parking_lot = { workspace = true }

[features]
default = ["binary"]
Expand Down
21 changes: 5 additions & 16 deletions crates/relayer/src/agent_store.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use std::{
collections::HashMap,
sync::{Arc, RwLock},
};
use parking_lot::RwLock;
use std::{collections::HashMap, sync::Arc};

use tokio::sync::mpsc::Sender;

Expand All @@ -20,12 +18,7 @@ pub struct AgentStore {

impl AgentStore {
pub fn add(&self, id: u64, conn_id: u64, tx: Sender<ProxyTunnelWrap>) {
if let Some(agent) = self
.agents
.write()
.expect("Should write agents")
.insert(id, AgentEntry { tx, conn_id })
{
if let Some(agent) = self.agents.write().insert(id, AgentEntry { tx, conn_id }) {
log::warn!(
"add new connection for agent {id}, old connection {} will deactivate",
agent.conn_id
Expand All @@ -34,15 +27,11 @@ impl AgentStore {
}

pub fn get(&self, id: u64) -> Option<Sender<ProxyTunnelWrap>> {
self.agents
.read()
.expect("Should write agents")
.get(&id)
.map(|entry| entry.tx.clone())
self.agents.read().get(&id).map(|entry| entry.tx.clone())
}

pub fn remove(&self, id: u64, conn_id: u64) -> bool {
let mut storage = self.agents.write().expect("Should write agents");
let mut storage = self.agents.write();

let current = storage.get(&id);
if let Some(entry) = current {
Expand Down
5 changes: 3 additions & 2 deletions crates/relayer/src/proxy_listener/cluster/vsocket.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use parking_lot::Mutex;
use std::{
fmt::Debug,
io::IoSliceMut,
net::{SocketAddr, SocketAddrV4},
ops::DerefMut,
pin::Pin,
sync::{Arc, Mutex},
sync::Arc,
task::{Context, Poll},
};

Expand Down Expand Up @@ -92,7 +93,7 @@ impl AsyncUdpSocket for VirtualUdpSocket {
bufs: &mut [IoSliceMut<'_>],
meta: &mut [RecvMeta],
) -> Poll<std::io::Result<usize>> {
let mut rx = self.rx.lock().expect("Should lock mutex");
let mut rx = self.rx.lock();
match rx.poll_recv(cx) {
std::task::Poll::Pending => std::task::Poll::Pending,
std::task::Poll::Ready(Some(pkt)) => {
Expand Down

0 comments on commit 5dd3b5a

Please sign in to comment.