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

Make unbounded a const function #67

Merged
merged 7 commits into from
Apr 13, 2024
Merged

Conversation

james7132
Copy link
Contributor

@james7132 james7132 commented Apr 13, 2024

This PR makes ConcurrentQueue::unbounded a const function. It'd be great if bounded could be const as well, but this would likely require static memory allocation support in const functions, which is currently not allowed by the compiler. This would enable smol-rs/async-executor#112 to be directly constructable in a const context (i.e. static/thread_local variable initialization without OnceLock). It might also allow unbounded async_channels to be constructed in a similar context.

src/unbounded.rs Outdated
@@ -149,6 +149,22 @@ pub struct Unbounded<T> {

impl<T> Unbounded<T> {
/// Creates a new unbounded queue.
#[cfg(not(loom))]
Copy link
Member

Choose a reason for hiding this comment

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

this sort of code duplication is very unfortunate, could we encapsulate that into a macro? (just the cfg + const switch)

Copy link
Collaborator

Choose a reason for hiding this comment

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

(Feel free to copy a helper macro used in my crates if needed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

src/lib.rs Outdated Show resolved Hide resolved
Co-authored-by: Taiki Endo <te316e89@gmail.com>
@james7132 james7132 requested review from fogti and taiki-e April 13, 2024 11:55
Copy link
Member

@notgull notgull left a comment

Choose a reason for hiding this comment

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

Thanks!

@notgull notgull merged commit 89a64f8 into smol-rs:master Apr 13, 2024
9 checks passed
@notgull notgull mentioned this pull request Apr 14, 2024
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.

None yet

4 participants