-
Notifications
You must be signed in to change notification settings - Fork 26
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
adding no_std
support
#59
Closed
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to use this unconditionally, even with
std
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaaactually this is a very good note! I was way too fast in replacing this. I found this in another implementation of channels, but there are some significant downsides. I could change the implementation to only use spin in no_std environments... Unfortunately that means I have to do this quite a lot:
Alternatively I could also use parking_lot as drop in replacement for std::rwlock since it should be faster as well.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can abstract this away so the
#cfg
is only done in a few places. i-e implement wrapper type forRwLock
that only provides the few methods we use.Let's consider that if we bump into any issues with my suggestion for a simple abstraction type. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a horrible thing:
Is this what u ment? If yes, I'd commit. The only problem I could not solve yet is that there is no need to compile spin if running with std feature enabled. Do you know how do disable a dependency if a feature is not selected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did, yes. However,
Hmm.. actually no and I think it's not possible. :( Cargo features are designed to be additive only.
Now we could consider
parking_lot
but:parking_lot
docs, I don't see any mention of nostd, norstd
feature listed there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow. What's the solution for only depending on
spin
when!std
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I've read this article.
I think the optimal solution would be to use spin for everything except std, wasm and single core no interrupt cores. Here it should check whether the lock is already locked and if so panic.
But as I see here, in concurrent-queue they also use spinning in
no_std
environment.I think the main problem emerges if you use a spin lock like this:
Then we would have a deadlock.
But since this is not happening, a spin lock should be ok for this library's internal usage in a
no_std
environment.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure but I'm talking about the dependency issue. How do we not have a dependency on
spin
whenstd
is enabled?This is a very usual footgun with locks. I don't think we need to do anything smart about this except ensure that we don't do this. Our locks are internal so we don't need to care about our users having such issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is no solution to this honestly. we could add a feature no_std that enables spin but it is not how other libraries handle it.
Another option would be to copy paste spin code into this crate and therefore getting rid of the dependency of spin. This could reduce compile time, but is not a really elegant solution in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's something I'd be interested in. How are other libs doing this?
Looks like
spin
has astd
feature:If I understand this correctly, we can use
spin
but enablestd
feature whenstd
is enabled on async-broadcast? If so, this would also eliminate the need for the abstractions.Yeah but if we can't come up with another solution, I'd still consider it as it's preferable to depending on an a completely unused crate. We'll only want to import the bits we need though so it could be a not-too-bad solution.