Annotate sync functions

pull/165/head
Andre Richter 2 years ago
parent 96ba61ace9
commit f452755919
No known key found for this signature in database
GPG Key ID: 2116C1AB102F615E

@ -313,7 +313,7 @@ diff -uNr 03_hacky_hello_world/src/synchronization.rs 04_safe_globals/src/synchr
+ type Data; + type Data;
+ +
+ /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. + /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
+ fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; + fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
+ } + }
+} +}
+ +
@ -354,7 +354,7 @@ diff -uNr 03_hacky_hello_world/src/synchronization.rs 04_safe_globals/src/synchr
+impl<T> interface::Mutex for NullLock<T> { +impl<T> interface::Mutex for NullLock<T> {
+ type Data = T; + type Data = T;
+ +
+ fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { + fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
+ // In a real lock, there would be code encapsulating this line that ensures that this + // In a real lock, there would be code encapsulating this line that ensures that this
+ // mutable reference will ever only be given out once at a time. + // mutable reference will ever only be given out once at a time.
+ let data = unsafe { &mut *self.data.get() }; + let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

@ -2605,7 +2605,7 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part
+++ 13_exceptions_part2_peripheral_IRQs/kernel/src/synchronization.rs +++ 13_exceptions_part2_peripheral_IRQs/kernel/src/synchronization.rs
@@ -28,6 +28,21 @@ @@ -28,6 +28,21 @@
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
+ +
+ /// A reader-writer exclusion type. + /// A reader-writer exclusion type.
@ -2617,10 +2617,10 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part
+ type Data; + type Data;
+ +
+ /// Grants temporary mutable access to the encapsulated data. + /// Grants temporary mutable access to the encapsulated data.
+ fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; + fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
+ +
+ /// Grants temporary immutable access to the encapsulated data. + /// Grants temporary immutable access to the encapsulated data.
+ fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; + fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
+ } + }
} }
@ -2682,7 +2682,7 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part
+impl<T> interface::Mutex for IRQSafeNullLock<T> { +impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
@@ -72,6 +110,50 @@ @@ -72,6 +110,50 @@
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -2695,7 +2695,7 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part
+impl<T> interface::ReadWriteEx for InitStateLock<T> { +impl<T> interface::ReadWriteEx for InitStateLock<T> {
+ type Data = T; + type Data = T;
+ +
+ fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { + fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
+ assert!( + assert!(
+ state::state_manager().is_init(), + state::state_manager().is_init(),
+ "InitStateLock::write called after kernel init phase" + "InitStateLock::write called after kernel init phase"
@ -2710,7 +2710,7 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part
f(data) f(data)
} }
+ +
+ fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { + fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
+ let data = unsafe { &*self.data.get() }; + let data = unsafe { &*self.data.get() };
+ +
+ f(data) + f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
/// A reader-writer exclusion type. /// A reader-writer exclusion type.
@ -38,10 +38,10 @@ pub mod interface {
type Data; type Data;
/// Grants temporary mutable access to the encapsulated data. /// Grants temporary mutable access to the encapsulated data.
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
/// Grants temporary immutable access to the encapsulated data. /// Grants temporary immutable access to the encapsulated data.
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
} }
} }
@ -105,7 +105,7 @@ use crate::{exception, state};
impl<T> interface::Mutex for IRQSafeNullLock<T> { impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -118,7 +118,7 @@ impl<T> interface::Mutex for IRQSafeNullLock<T> {
impl<T> interface::ReadWriteEx for InitStateLock<T> { impl<T> interface::ReadWriteEx for InitStateLock<T> {
type Data = T; type Data = T;
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
assert!( assert!(
state::state_manager().is_init(), state::state_manager().is_init(),
"InitStateLock::write called after kernel init phase" "InitStateLock::write called after kernel init phase"
@ -133,7 +133,7 @@ impl<T> interface::ReadWriteEx for InitStateLock<T> {
f(data) f(data)
} }
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
let data = unsafe { &*self.data.get() }; let data = unsafe { &*self.data.get() };
f(data) f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
/// A reader-writer exclusion type. /// A reader-writer exclusion type.
@ -38,10 +38,10 @@ pub mod interface {
type Data; type Data;
/// Grants temporary mutable access to the encapsulated data. /// Grants temporary mutable access to the encapsulated data.
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
/// Grants temporary immutable access to the encapsulated data. /// Grants temporary immutable access to the encapsulated data.
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
} }
} }
@ -105,7 +105,7 @@ use crate::{exception, state};
impl<T> interface::Mutex for IRQSafeNullLock<T> { impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -118,7 +118,7 @@ impl<T> interface::Mutex for IRQSafeNullLock<T> {
impl<T> interface::ReadWriteEx for InitStateLock<T> { impl<T> interface::ReadWriteEx for InitStateLock<T> {
type Data = T; type Data = T;
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
assert!( assert!(
state::state_manager().is_init(), state::state_manager().is_init(),
"InitStateLock::write called after kernel init phase" "InitStateLock::write called after kernel init phase"
@ -133,7 +133,7 @@ impl<T> interface::ReadWriteEx for InitStateLock<T> {
f(data) f(data)
} }
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
let data = unsafe { &*self.data.get() }; let data = unsafe { &*self.data.get() };
f(data) f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
/// A reader-writer exclusion type. /// A reader-writer exclusion type.
@ -38,10 +38,10 @@ pub mod interface {
type Data; type Data;
/// Grants temporary mutable access to the encapsulated data. /// Grants temporary mutable access to the encapsulated data.
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
/// Grants temporary immutable access to the encapsulated data. /// Grants temporary immutable access to the encapsulated data.
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
} }
} }
@ -105,7 +105,7 @@ use crate::{exception, state};
impl<T> interface::Mutex for IRQSafeNullLock<T> { impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -118,7 +118,7 @@ impl<T> interface::Mutex for IRQSafeNullLock<T> {
impl<T> interface::ReadWriteEx for InitStateLock<T> { impl<T> interface::ReadWriteEx for InitStateLock<T> {
type Data = T; type Data = T;
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
assert!( assert!(
state::state_manager().is_init(), state::state_manager().is_init(),
"InitStateLock::write called after kernel init phase" "InitStateLock::write called after kernel init phase"
@ -133,7 +133,7 @@ impl<T> interface::ReadWriteEx for InitStateLock<T> {
f(data) f(data)
} }
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
let data = unsafe { &*self.data.get() }; let data = unsafe { &*self.data.get() };
f(data) f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
/// A reader-writer exclusion type. /// A reader-writer exclusion type.
@ -38,10 +38,10 @@ pub mod interface {
type Data; type Data;
/// Grants temporary mutable access to the encapsulated data. /// Grants temporary mutable access to the encapsulated data.
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
/// Grants temporary immutable access to the encapsulated data. /// Grants temporary immutable access to the encapsulated data.
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
} }
} }
@ -105,7 +105,7 @@ use crate::{exception, state};
impl<T> interface::Mutex for IRQSafeNullLock<T> { impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -118,7 +118,7 @@ impl<T> interface::Mutex for IRQSafeNullLock<T> {
impl<T> interface::ReadWriteEx for InitStateLock<T> { impl<T> interface::ReadWriteEx for InitStateLock<T> {
type Data = T; type Data = T;
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
assert!( assert!(
state::state_manager().is_init(), state::state_manager().is_init(),
"InitStateLock::write called after kernel init phase" "InitStateLock::write called after kernel init phase"
@ -133,7 +133,7 @@ impl<T> interface::ReadWriteEx for InitStateLock<T> {
f(data) f(data)
} }
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
let data = unsafe { &*self.data.get() }; let data = unsafe { &*self.data.get() };
f(data) f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
/// A reader-writer exclusion type. /// A reader-writer exclusion type.
@ -38,10 +38,10 @@ pub mod interface {
type Data; type Data;
/// Grants temporary mutable access to the encapsulated data. /// Grants temporary mutable access to the encapsulated data.
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
/// Grants temporary immutable access to the encapsulated data. /// Grants temporary immutable access to the encapsulated data.
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
} }
} }
@ -105,7 +105,7 @@ use crate::{exception, state};
impl<T> interface::Mutex for IRQSafeNullLock<T> { impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -118,7 +118,7 @@ impl<T> interface::Mutex for IRQSafeNullLock<T> {
impl<T> interface::ReadWriteEx for InitStateLock<T> { impl<T> interface::ReadWriteEx for InitStateLock<T> {
type Data = T; type Data = T;
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
assert!( assert!(
state::state_manager().is_init(), state::state_manager().is_init(),
"InitStateLock::write called after kernel init phase" "InitStateLock::write called after kernel init phase"
@ -133,7 +133,7 @@ impl<T> interface::ReadWriteEx for InitStateLock<T> {
f(data) f(data)
} }
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
let data = unsafe { &*self.data.get() }; let data = unsafe { &*self.data.get() };
f(data) f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
/// A reader-writer exclusion type. /// A reader-writer exclusion type.
@ -38,10 +38,10 @@ pub mod interface {
type Data; type Data;
/// Grants temporary mutable access to the encapsulated data. /// Grants temporary mutable access to the encapsulated data.
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
/// Grants temporary immutable access to the encapsulated data. /// Grants temporary immutable access to the encapsulated data.
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R; fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R;
} }
} }
@ -105,7 +105,7 @@ use crate::{exception, state};
impl<T> interface::Mutex for IRQSafeNullLock<T> { impl<T> interface::Mutex for IRQSafeNullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };
@ -118,7 +118,7 @@ impl<T> interface::Mutex for IRQSafeNullLock<T> {
impl<T> interface::ReadWriteEx for InitStateLock<T> { impl<T> interface::ReadWriteEx for InitStateLock<T> {
type Data = T; type Data = T;
fn write<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn write<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
assert!( assert!(
state::state_manager().is_init(), state::state_manager().is_init(),
"InitStateLock::write called after kernel init phase" "InitStateLock::write called after kernel init phase"
@ -133,7 +133,7 @@ impl<T> interface::ReadWriteEx for InitStateLock<T> {
f(data) f(data)
} }
fn read<R>(&self, f: impl FnOnce(&Self::Data) -> R) -> R { fn read<'a, R>(&'a self, f: impl FnOnce(&'a Self::Data) -> R) -> R {
let data = unsafe { &*self.data.get() }; let data = unsafe { &*self.data.get() };
f(data) f(data)

@ -26,7 +26,7 @@ pub mod interface {
type Data; type Data;
/// Locks the mutex and grants the closure temporary mutable access to the wrapped data. /// Locks the mutex and grants the closure temporary mutable access to the wrapped data.
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R; fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R;
} }
} }
@ -67,7 +67,7 @@ impl<T> NullLock<T> {
impl<T> interface::Mutex for NullLock<T> { impl<T> interface::Mutex for NullLock<T> {
type Data = T; type Data = T;
fn lock<R>(&self, f: impl FnOnce(&mut Self::Data) -> R) -> R { fn lock<'a, R>(&'a self, f: impl FnOnce(&'a mut Self::Data) -> R) -> R {
// In a real lock, there would be code encapsulating this line that ensures that this // In a real lock, there would be code encapsulating this line that ensures that this
// mutable reference will ever only be given out once at a time. // mutable reference will ever only be given out once at a time.
let data = unsafe { &mut *self.data.get() }; let data = unsafe { &mut *self.data.get() };

Loading…
Cancel
Save