Skip to content

Commit

Permalink
Use futures_task::ArcWake again now that it's fixed
Browse files Browse the repository at this point in the history
Avoids one unnecessary atomic operation per wake.

Fixes #133
  • Loading branch information
sdroege committed Dec 10, 2024
1 parent b78f952 commit 1e0baad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
29 changes: 15 additions & 14 deletions Cargo.lock.msrv

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ features = ["async-std-runtime", "tokio-runtime", "gio-runtime", "async-tls", "a
[dependencies]
log = "0.4"
futures-core = { version = "0.3", default-features = false }
futures-task = { version = "0.3.31", default-features = false }
atomic-waker = { version = "1.1", default-features = false }
futures-io = { version = "0.3", default-features = false, features = ["std"] }
pin-project-lite = "0.2"
Expand Down
19 changes: 8 additions & 11 deletions src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
use log::*;
use std::io::{Read, Write};
use std::pin::Pin;
use std::task::{Context, Poll, Wake, Waker};
use std::task::{Context, Poll, Waker};

use atomic_waker::AtomicWaker;
use futures_io::{AsyncRead, AsyncWrite};
use futures_task::{waker_ref, ArcWake};
use std::sync::Arc;
use tungstenite::Error as WsError;

Expand Down Expand Up @@ -109,14 +110,10 @@ struct WakerProxy {
write_waker: AtomicWaker,
}

impl Wake for WakerProxy {
fn wake(self: Arc<Self>) {
self.wake_by_ref()
}

fn wake_by_ref(self: &Arc<Self>) {
self.read_waker.wake();
self.write_waker.wake();
impl ArcWake for WakerProxy {
fn wake_by_ref(arc_self: &Arc<Self>) {
arc_self.read_waker.wake();
arc_self.write_waker.wake();
}
}

Expand All @@ -131,8 +128,8 @@ where
#[cfg(feature = "verbose-logging")]
trace!("{}:{} AllowStd.with_context", file!(), line!());
let waker = match kind {
ContextWaker::Read => Waker::from(self.read_waker_proxy.clone()),
ContextWaker::Write => Waker::from(self.write_waker_proxy.clone()),
ContextWaker::Read => waker_ref(&self.read_waker_proxy),
ContextWaker::Write => waker_ref(&self.write_waker_proxy),
};
let mut context = Context::from_waker(&waker);
f(&mut context, Pin::new(&mut self.inner))
Expand Down

0 comments on commit 1e0baad

Please sign in to comment.