futures-rs icon indicating copy to clipboard operation
futures-rs copied to clipboard

Support shared futures on no_std

Open adavis628 opened this issue 1 year ago • 1 comments

Currently, Shared futures are only available when the std feature is enabled because they use std::sync::Mutex internally. This PR changes this so that Shared futures will fall back to using a spinlock when std is not enabled.

Alternatively, Shared could be changed to be generic over a mutex trait (e.g. lock_api::RawMutex, though it isn't implemented for std::sync::Mutex) to allow arbitrary user implementations.

adavis628 avatar Jul 02 '24 21:07 adavis628

Thanks for the PR. I would prefer not to use spinlock by default around operations that would involve allocations even if it is no_std-only.

That said, it might be fine if this is an optional feature and spinlock is used only when std is disabled and the feature is explicitly enabled.

taiki-e avatar Oct 02 '24 13:10 taiki-e

I moved the spinlock behind an optional spin feature that will use a spinlock when std is disabled.

adavis628 avatar Dec 23 '24 00:12 adavis628