Skip to content

Commit 688b492

Browse files
Allow the taken flag to be optimized out
1 parent 32634e4 commit 688b492

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/peripheral/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,17 @@ pub struct Peripherals {
150150
// NOTE `no_mangle` is used here to prevent linking different minor versions of this crate as that
151151
// would let you `take` the core peripherals more than once (one per minor version)
152152
#[no_mangle]
153-
static mut CORE_PERIPHERALS: bool = false;
153+
static CORE_PERIPHERALS: () = ();
154+
155+
/// Set to `true` when `take` or `steal` was called to make `Peripherals` a singleton.
156+
static mut TAKEN: bool = false;
154157

155158
impl Peripherals {
156159
/// Returns all the core peripherals *once*
157160
#[inline]
158161
pub fn take() -> Option<Self> {
159162
interrupt::free(|_| {
160-
if unsafe { CORE_PERIPHERALS } {
163+
if unsafe { TAKEN } {
161164
None
162165
} else {
163166
Some(unsafe { Peripherals::steal() })
@@ -168,7 +171,7 @@ impl Peripherals {
168171
/// Unchecked version of `Peripherals::take`
169172
#[inline]
170173
pub unsafe fn steal() -> Self {
171-
CORE_PERIPHERALS = true;
174+
TAKEN = true;
172175

173176
Peripherals {
174177
CBP: CBP {

0 commit comments

Comments
 (0)