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

bitfield: some kind of AtomicBitfield? #305

Open
hawkw opened this issue Aug 31, 2022 · 0 comments
Open

bitfield: some kind of AtomicBitfield? #305

hawkw opened this issue Aug 31, 2022 · 0 comments
Labels
crate/bitfield Related to the `mycelium-bitfield` crate kind/enhancement New feature or request

Comments

@hawkw
Copy link
Owner

hawkw commented Aug 31, 2022

it would be cool to have a way to simplify storing mycelium-bitfield bitfield types in atomics.

i'm not sure whether the best design is something like this, where the T-typed bitfield types are treated as "snapshots" that can be loaded/stored in the atomic:

// `T` is a `mycelium-bitfield` generated type
pub struct AtomicBitfield<T> { 
  // ...
}

impl<T> AtomicBitfield<T> {
   pub fn load(&self, ordering: Ordering) -> T { 
       // ...
   }

   pub fn compare_exchange(&self, curr: T, next: T, success: Ordering, failure: Ordering) -> Result<T, T> {
      // ...
   }

   // and so on...
}  

or, something like this:

mycelium_bitfield::bitfield! {
   pub struct MyBitfield<AtomicUsize> {
      const FOO = 1;
      const BAR = 1;
      // ...
  }
}

and having it generate versions of the get and set methods that take &self when the bits type is an atomic.

I think the first one is actually better, as it allows more complicated CAS patterns that toggle multiple bits in one atomic op...

@hawkw hawkw added kind/enhancement New feature or request crate/bitfield Related to the `mycelium-bitfield` crate labels Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/bitfield Related to the `mycelium-bitfield` crate kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant