Skip to content

Commit b7ff5f7

Browse files
jonas-schievinkadamgreig
authored andcommitted
Allow the taken flag to be optimized out
1 parent cb6a61a commit b7ff5f7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/peripheral/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,17 @@ pub struct Peripherals {
143143
// NOTE `no_mangle` is used here to prevent linking different minor versions of this crate as that
144144
// would let you `take` the core peripherals more than once (one per minor version)
145145
#[no_mangle]
146-
static mut CORE_PERIPHERALS: bool = false;
146+
static CORE_PERIPHERALS: () = ();
147+
148+
/// Set to `true` when `take` or `steal` was called to make `Peripherals` a singleton.
149+
static mut TAKEN: bool = false;
147150

148151
impl Peripherals {
149152
/// Returns all the core peripherals *once*
150153
#[inline]
151154
pub fn take() -> Option<Self> {
152155
interrupt::free(|_| {
153-
if unsafe { CORE_PERIPHERALS } {
156+
if unsafe { TAKEN } {
154157
None
155158
} else {
156159
Some(unsafe { Peripherals::steal() })
@@ -161,7 +164,7 @@ impl Peripherals {
161164
/// Unchecked version of `Peripherals::take`
162165
#[inline]
163166
pub unsafe fn steal() -> Self {
164-
CORE_PERIPHERALS = true;
167+
TAKEN = true;
165168

166169
Peripherals {
167170
CBP: CBP {

0 commit comments

Comments
 (0)