-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added proof of concept for atomic bitflags
- Loading branch information
Showing
5 changed files
with
199 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Generate the user-facing atomic flags type. | ||
//! | ||
//! The code here belongs to the end-user, so new trait implementations and methods can't be | ||
//! added without potentially breaking users. | ||
|
||
#[macro_export(local_inner_macros)] | ||
#[doc(hidden)] | ||
macro_rules! __declare_atomic_bitflags { | ||
( | ||
$(#[$outer:meta])* | ||
$vis:vis struct $AtomicBitFlags:ident : $Flags:ident | ||
) => { | ||
$(#[$outer])* | ||
$vis struct $AtomicBitFlags(<<$Flags as $crate::Flags>::Bits as $crate::HasAtomic>::Atomic); | ||
|
||
impl $crate::AtomicFlags for $AtomicBitFlags { | ||
type Flags = $Flags; | ||
type AtomicBits = <<$Flags as $crate::Flags>::Bits as $crate::HasAtomic>::Atomic; | ||
|
||
fn atomic_bits(&self) -> &Self::AtomicBits { | ||
&self.0 | ||
} | ||
fn from_bits_retain(bits: <Self::Flags as $crate::Flags>::Bits) -> Self { | ||
Self(Self::AtomicBits::from(bits)) | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use bitflags::{bitflags, AtomicFlags}; | ||
|
||
bitflags! { | ||
#[atomic_attr(derive(Default))] | ||
#[atomic(MyAtomicFlags)] | ||
pub struct MyFlags: u32 { | ||
const A = 1; | ||
const B = 2; | ||
} | ||
} | ||
|
||
fn main() { | ||
let flags = MyAtomicFlags::default(); | ||
flags.fetch_insert(MyFlags::A, core::sync::atomic::Ordering::Relaxed); | ||
} |