From b5d12e0afc9e792a4aa81ee54bde97a8b9815c58 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 4 Dec 2018 12:08:00 +0100 Subject: [PATCH] Don't wrap yamux::Connection in a mutex (#719) Get rid of double mutex * Use inherent `poll()` that takes an immutable ref * Remove parking_lot dependency from yamux * Update muxers/yamux/Cargo.toml Co-Authored-By: dvdplm --- muxers/yamux/Cargo.toml | 3 +-- muxers/yamux/src/lib.rs | 14 ++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 446327ca..d2e2277a 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -9,6 +9,5 @@ bytes = "0.4" futures = "0.1" libp2p-core = { path = "../../core" } log = "0.4" -parking_lot = "0.7" tokio-io = "0.1" -yamux = "0.1" +yamux = "0.1.1" diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 29816b96..4ab58d74 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -23,27 +23,25 @@ extern crate futures; #[macro_use] extern crate log; extern crate libp2p_core; -extern crate parking_lot; extern crate tokio_io; extern crate yamux; use bytes::Bytes; use futures::{future::{self, FutureResult}, prelude::*}; use libp2p_core::{muxing::Shutdown, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}}; -use parking_lot::Mutex; use std::{io, iter}; use std::io::{Error as IoError}; use tokio_io::{AsyncRead, AsyncWrite}; -pub struct Yamux(Mutex>); +pub struct Yamux(yamux::Connection); impl Yamux where C: AsyncRead + AsyncWrite + 'static { pub fn new(c: C, cfg: yamux::Config, mode: yamux::Mode) -> Self { - Yamux(Mutex::new(yamux::Connection::new(c, cfg, mode))) + Yamux(yamux::Connection::new(c, cfg, mode)) } } @@ -56,7 +54,7 @@ where #[inline] fn poll_inbound(&self) -> Poll, IoError> { - match self.0.lock().poll() { + match self.0.poll() { Err(e) => { error!("connection error: {}", e); Err(io::Error::new(io::ErrorKind::Other, e)) @@ -69,7 +67,7 @@ where #[inline] fn open_outbound(&self) -> Self::OutboundSubstream { - let stream = self.0.lock().open_stream().map_err(|e| io::Error::new(io::ErrorKind::Other, e)); + let stream = self.0.open_stream().map_err(|e| io::Error::new(io::ErrorKind::Other, e)); future::result(stream) } @@ -108,12 +106,12 @@ where #[inline] fn shutdown(&self, _: Shutdown) -> Poll<(), IoError> { - self.0.lock().shutdown() + self.0.shutdown() } #[inline] fn flush_all(&self) -> Poll<(), IoError> { - self.0.lock().flush() + self.0.flush() } }