Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some async blocks with manual futures #34

Merged
merged 5 commits into from
Dec 29, 2022

Conversation

notgull
Copy link
Member

@notgull notgull commented Dec 16, 2022

The goal of this PR is to resolve #4 by adding manually-implemented futures to Mutex, RwLock, Barrier and Semaphore, similar to smol-rs/async-channel#33. This aim of this PR is to improve semantics for when poll is the only means available to poll a future. The main downside is that is replaces the elegant async blocks with some more garish manual futures, but I tried to keep the semantics and ordering of logic the same throughout.

I avoided adding implementations for OnceCell, since with the closures and self-referential ideas it's not possible to implement without either a significant amount of hard-to-check unsafe code or overextensive heap allocation.

Closes #4
Closes #5

@notgull
Copy link
Member Author

notgull commented Dec 16, 2022

I'm not sure why MIRI is detecting a deadlock, it doesn't seem to deadlock during the main tests. I'll look into it. Fixed!

@notgull notgull requested a review from taiki-e December 24, 2022 03:07
Copy link
Collaborator

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/semaphore.rs Show resolved Hide resolved
src/lib.rs Outdated
Comment on lines 18 to 22
pub use barrier::{Barrier, BarrierWaitResult};
pub use mutex::{Mutex, MutexGuard, MutexGuardArc};
pub use mutex::{Lock, LockArc, Mutex, MutexGuard, MutexGuardArc};
pub use once_cell::OnceCell;
pub use rwlock::{RwLock, RwLockReadGuard, RwLockUpgradableReadGuard, RwLockWriteGuard};
pub use semaphore::{Semaphore, SemaphoreGuard, SemaphoreGuardArc};
pub use semaphore::{Acquire, AcquireArc, Semaphore, SemaphoreGuard, SemaphoreGuardArc};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the futures from rwlock and barrier not exported?

That said, exporting everything might make the documentation less readable... (FYI, tokio has modules for named futures. futures exposes each of the sub-modules or gives a verbose name.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a futures module that contains all of the exported named futures.

src/mutex.rs Outdated Show resolved Hide resolved
@notgull notgull merged commit 15049aa into master Dec 29, 2022
@notgull notgull deleted the notgull/manual-futures branch December 29, 2022 04:30
@notgull notgull mentioned this pull request Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: poll_lock(cx) for Mutex
2 participants