Skip to content

Commit

Permalink
Drop futures::Stream impl
Browse files Browse the repository at this point in the history
This isn't used. We could opt for implementing FusedFuture and
FusedStream, but these traits seem incoherent [1] and are due
to removal for futures-core 1.0 [2]. They're not needed, so just
get rid of them.

[1] rust-lang/futures-rs#2779
[2] rust-lang/futures-rs#2207
  • Loading branch information
darsto committed Apr 21, 2024
1 parent 03d973a commit 2b18829
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
8 changes: 0 additions & 8 deletions src/atomic_waiter.rs
Expand Up @@ -4,7 +4,6 @@ use core::sync::atomic::{AtomicBool, Ordering};
use core::task::{Context, Poll};

use futures::task::AtomicWaker;
use futures::Stream;

/// Thin wrapper over [`futures::task::AtomicWaker`]. This represents a
/// Send + Sync Future that can be completed by calling its wake() method.
Expand Down Expand Up @@ -78,10 +77,3 @@ impl Future for AtomicWaiter {
self.poll_const(cx)
}
}

impl Stream for AtomicWaiter {
type Item = ();
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.poll(cx).map(Some)
}
}
23 changes: 5 additions & 18 deletions src/lib.rs
Expand Up @@ -7,8 +7,6 @@ use core::ptr::null_mut;
use core::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
use core::task::{Context, Poll};

use futures::Stream;

pub mod atomic_waiter;
use atomic_waiter::AtomicWaiter;

Expand Down Expand Up @@ -221,28 +219,17 @@ impl<'m, const M: usize, T> Future for BorrowMutexLender<'m, M, T> {
// And the same lend_waiter is polled in LendGuard, which could have
// consumed both of those wakes. Before we start endlessly polling now,
// check if we're ready
if !self.mutex.borrowers.is_empty() {
return Poll::Ready(());
}

if self.mutex.lend_waiter.poll_const(cx) == Poll::Pending {
return Poll::Pending;
#[allow(clippy::collapsible_if)]
if self.mutex.borrowers.is_empty() {
if self.mutex.lend_waiter.poll_const(cx) == Poll::Pending {
return Poll::Pending;
}
}

// even if dropped on the borrowing side, borrowers stay in the queue
// until us (the lender) pops them
assert!(!self.mutex.borrowers.is_empty());
Poll::Ready(())
}
}

impl<'m, const M: usize, T> Stream for BorrowMutexLender<'m, M, T> {
type Item = ();
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.poll(cx).map(Some)
}
}

pub struct BorrowMutexLendGuard<'l, const M: usize, T> {
mutex: *const BorrowMutex<M, T>,
borrow: &'l BorrowMutexRef,
Expand Down

0 comments on commit 2b18829

Please sign in to comment.