Address comments

This commit is contained in:
Julien Cretin
2022-03-04 16:09:04 +01:00
parent d16811fe25
commit 2e3034193e
2 changed files with 11 additions and 12 deletions

21
src/env/tock/mod.rs vendored
View File

@@ -27,19 +27,18 @@ pub struct TockEnv {
impl TockEnv { impl TockEnv {
/// Returns the unique instance of the Tock environment. /// Returns the unique instance of the Tock environment.
/// ///
/// This function returns `Some` the first time it is called. Afterwards, it repeatedly returns /// # Panics
/// `None`. ///
pub fn new() -> Option<Self> { /// - If called a second time.
pub fn new() -> Self {
// Make sure the environment was not already taken. // Make sure the environment was not already taken.
static TAKEN: AtomicBool = AtomicBool::new(false); static TAKEN: AtomicBool = AtomicBool::new(false);
if TAKEN.fetch_or(true, Ordering::SeqCst) { assert!(!TAKEN.fetch_or(true, Ordering::SeqCst));
return None; TockEnv {
}
Some(TockEnv {
rng: TockRng256 {}, rng: TockRng256 {},
storage: false, storage: false,
upgrade_storage: false, upgrade_storage: false,
}) }
} }
} }
@@ -47,11 +46,11 @@ impl TockEnv {
/// ///
/// # Safety /// # Safety
/// ///
/// It is probably technically memory-safe to hame multiple storage instances at the same time, but /// It is probably technically memory-safe to have multiple storage instances at the same time, but
/// for extra precaution we mark the function as unsafe. To ensure correct usage, this function /// for extra precaution we mark the function as unsafe. To ensure correct usage, this function
/// should only be called if the previous storage instance was dropped. /// should only be called if the previous storage instance was dropped.
// This function is exposed for example binaries testing the hardware. This could probably be // This function is exposed to example binaries testing the hardware. This could probably be cleaned
// cleaned up by having the persistent store return its storage. // up by having the persistent store return its storage.
pub unsafe fn steal_storage() -> StorageResult<SyscallStorage> { pub unsafe fn steal_storage() -> StorageResult<SyscallStorage> {
SyscallStorage::new() SyscallStorage::new()
} }

View File

@@ -57,7 +57,7 @@ fn main() {
} }
let boot_time = timer.get_current_clock().flex_unwrap(); let boot_time = timer.get_current_clock().flex_unwrap();
let env = TockEnv::new().unwrap(); let env = TockEnv::new();
let mut ctap = ctap2::Ctap::new(env, boot_time); let mut ctap = ctap2::Ctap::new(env, boot_time);
let mut led_counter = 0; let mut led_counter = 0;