WIP: Added atomic bitflags generation #391
No reviewers
Labels
No labels
bug
good first issue
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-bitflags/bitflags!391
Loading…
Reference in a new issue
No description provided.
Delete branch "main"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The idea is to enable the macro to create a wrapper type for atomic flags, using an attribute as opt in. All the main flags logic will still be handled by the regular flags, with the atomic flags only acting as an adapter to some atomic int type.
Some open questions to me are:
Hi @f-gagel 👋 Thanks for the PR! I've tried to avoid introducing any custom attributes to
bitflagsto keep the implementation from becoming too complex.I had a look at whether we could already do this with a custom
Bitsimplementation and we can't really, because you'll want to operate on non-atomic integers, but store the results atomically.Depending on your use-case, you could declare your bitflags type over a regular integer type, and just load/store it from a shared atomic integer as necessary. That would neatly separate storage concerns from the flags type itself, and let you do multiple bitwise operations on the flags value before needing to use atomics to store them.
Hi. Thanks for the feedback!
I understand the concern about keeping the macro straightforward. For the atomic storage would a generic wrapper type
Atomic<Flags>be an option? My goal with this is to not just enable load and store but also fetch_* operations for flags or would that be outside the scope of the bitflags crate?Hi @f-gagel, I've been able to accomplish something similar with
atomigby#[derive(Atom, AtomLogic)]ing. It doesn't result in exactly the same API as this PR, but it's pretty similar. You can doAtomic<Flags>and things like.fetch_or.Thanks @kkysen 👍 That seems like a good way to go here.
I think this isn't something we'll be able to support in
bitflagsdirectly due to the additional feature complexity so will go ahead and close this one, but I appreciate the time you've spent putting an implementation together.Hi, I understand that you want to avoid that extra complexity. Thank you for your consideration.
@kkysen
atomigworks really nicely for this case. Thanks for pointing it out.To anyone looking for how to get my preferred API, here's the neccessary glue: https://gist.github.com/f-gagel/7cb44e6ce27022cf2991b11d27044610
Pull request closed