Skip to content

Commit b93f133

Browse files
committed
fix atomics feature
1 parent 615f093 commit b93f133

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

src/generate/generic_atomic.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod atomic {
2+
use super::*;
23
use portable_atomic::Ordering;
34

45
pub trait AtomicOperations {
@@ -35,67 +36,66 @@ mod atomic {
3536
// Enable 64-bit atomics for 64-bit RISCV
3637
#[cfg(any(target_pointer_width = "64", target_has_atomic = "64"))]
3738
impl_atomics!(u64, portable_atomic::AtomicU64);
38-
}
39-
use atomic::AtomicOperations;
4039

41-
impl<REG: Readable + Writable> Reg<REG>
42-
where
43-
REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>,
44-
{
45-
/// Set high every bit in the register that was set in the write proxy. Leave other bits
46-
/// untouched. The write is done in a single atomic instruction.
47-
///
48-
/// # Safety
49-
///
50-
/// The resultant bit pattern may not be valid for the register.
51-
#[inline(always)]
52-
pub unsafe fn set_bits<F>(&self, f: F)
40+
impl<REG: Readable + Writable> Reg<REG>
5341
where
54-
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
42+
REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>,
5543
{
56-
let bits = f(&mut REG::Writer::from(W {
57-
bits: Default::default(),
58-
_reg: marker::PhantomData,
59-
}))
60-
.bits;
61-
REG::Ux::atomic_or(self.register.as_ptr(), bits);
62-
}
44+
/// Set high every bit in the register that was set in the write proxy. Leave other bits
45+
/// untouched. The write is done in a single atomic instruction.
46+
///
47+
/// # Safety
48+
///
49+
/// The resultant bit pattern may not be valid for the register.
50+
#[inline(always)]
51+
pub unsafe fn set_bits<F>(&self, f: F)
52+
where
53+
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
54+
{
55+
let bits = f(&mut REG::Writer::from(W {
56+
bits: Default::default(),
57+
_reg: marker::PhantomData,
58+
}))
59+
.bits;
60+
REG::Ux::atomic_or(self.register.as_ptr(), bits);
61+
}
6362

64-
/// Clear every bit in the register that was cleared in the write proxy. Leave other bits
65-
/// untouched. The write is done in a single atomic instruction.
66-
///
67-
/// # Safety
68-
///
69-
/// The resultant bit pattern may not be valid for the register.
70-
#[inline(always)]
71-
pub unsafe fn clear_bits<F>(&self, f: F)
72-
where
73-
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
74-
{
75-
let bits = f(&mut REG::Writer::from(W {
76-
bits: !REG::Ux::default(),
77-
_reg: marker::PhantomData,
78-
}))
79-
.bits;
80-
REG::Ux::atomic_and(self.register.as_ptr(), bits);
81-
}
63+
/// Clear every bit in the register that was cleared in the write proxy. Leave other bits
64+
/// untouched. The write is done in a single atomic instruction.
65+
///
66+
/// # Safety
67+
///
68+
/// The resultant bit pattern may not be valid for the register.
69+
#[inline(always)]
70+
pub unsafe fn clear_bits<F>(&self, f: F)
71+
where
72+
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
73+
{
74+
let bits = f(&mut REG::Writer::from(W {
75+
bits: !REG::Ux::default(),
76+
_reg: marker::PhantomData,
77+
}))
78+
.bits;
79+
REG::Ux::atomic_and(self.register.as_ptr(), bits);
80+
}
8281

83-
/// Toggle every bit in the register that was set in the write proxy. Leave other bits
84-
/// untouched. The write is done in a single atomic instruction.
85-
///
86-
/// # Safety
87-
///
88-
/// The resultant bit pattern may not be valid for the register.
89-
#[inline(always)]
90-
pub unsafe fn toggle_bits<F>(&self, f: F)
91-
where
92-
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
93-
{
94-
let bits = f(&mut REG::Writer::from(W {
95-
bits: Default::default(),
96-
_reg: marker::PhantomData,
97-
}))
98-
.bits;
99-
REG::Ux::atomic_xor(self.register.as_ptr(), bits);
82+
/// Toggle every bit in the register that was set in the write proxy. Leave other bits
83+
/// untouched. The write is done in a single atomic instruction.
84+
///
85+
/// # Safety
86+
///
87+
/// The resultant bit pattern may not be valid for the register.
88+
#[inline(always)]
89+
pub unsafe fn toggle_bits<F>(&self, f: F)
90+
where
91+
F: FnOnce(&mut REG::Writer) -> &mut W<REG>,
92+
{
93+
let bits = f(&mut REG::Writer::from(W {
94+
bits: Default::default(),
95+
_reg: marker::PhantomData,
96+
}))
97+
.bits;
98+
REG::Ux::atomic_xor(self.register.as_ptr(), bits);
99+
}
100100
}
101101
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy