From f45275591963e34c6f7b93e8109ad0512f08587c Mon Sep 17 00:00:00 2001 From: Andre Richter Date: Tue, 17 May 2022 23:24:33 +0200 Subject: [PATCH] Annotate sync functions --- 04_safe_globals/README.md | 4 ++-- 04_safe_globals/src/synchronization.rs | 4 ++-- 05_drivers_gpio_uart/src/synchronization.rs | 4 ++-- 06_uart_chainloader/src/synchronization.rs | 4 ++-- 07_timestamps/src/synchronization.rs | 4 ++-- 08_hw_debug_JTAG/src/synchronization.rs | 4 ++-- 09_privilege_level/src/synchronization.rs | 4 ++-- .../src/synchronization.rs | 4 ++-- .../src/synchronization.rs | 4 ++-- 12_integrated_testing/kernel/src/synchronization.rs | 4 ++-- 13_exceptions_part2_peripheral_IRQs/README.md | 12 ++++++------ .../kernel/src/synchronization.rs | 12 ++++++------ .../kernel/src/synchronization.rs | 12 ++++++------ .../kernel/src/synchronization.rs | 12 ++++++------ .../kernel/src/synchronization.rs | 12 ++++++------ 17_kernel_symbols/kernel/src/synchronization.rs | 12 ++++++------ 18_backtrace/kernel/src/synchronization.rs | 12 ++++++------ X1_JTAG_boot/src/synchronization.rs | 4 ++-- 18 files changed, 64 insertions(+), 64 deletions(-) diff --git a/04_safe_globals/README.md b/04_safe_globals/README.md index 58c14dc2..b34c04f9 100644 --- a/04_safe_globals/README.md +++ b/04_safe_globals/README.md @@ -313,7 +313,7 @@ diff -uNr 03_hacky_hello_world/src/synchronization.rs 04_safe_globals/src/synchr + type Data; + + /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. -+ fn lock(&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 interface::Mutex for NullLock { + type Data = T; + -+ fn lock(&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 + // mutable reference will ever only be given out once at a time. + let data = unsafe { &mut *self.data.get() }; diff --git a/04_safe_globals/src/synchronization.rs b/04_safe_globals/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/04_safe_globals/src/synchronization.rs +++ b/04_safe_globals/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/05_drivers_gpio_uart/src/synchronization.rs b/05_drivers_gpio_uart/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/05_drivers_gpio_uart/src/synchronization.rs +++ b/05_drivers_gpio_uart/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/06_uart_chainloader/src/synchronization.rs b/06_uart_chainloader/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/06_uart_chainloader/src/synchronization.rs +++ b/06_uart_chainloader/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/07_timestamps/src/synchronization.rs b/07_timestamps/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/07_timestamps/src/synchronization.rs +++ b/07_timestamps/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/08_hw_debug_JTAG/src/synchronization.rs b/08_hw_debug_JTAG/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/08_hw_debug_JTAG/src/synchronization.rs +++ b/08_hw_debug_JTAG/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/09_privilege_level/src/synchronization.rs b/09_privilege_level/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/09_privilege_level/src/synchronization.rs +++ b/09_privilege_level/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/10_virtual_mem_part1_identity_mapping/src/synchronization.rs b/10_virtual_mem_part1_identity_mapping/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/10_virtual_mem_part1_identity_mapping/src/synchronization.rs +++ b/10_virtual_mem_part1_identity_mapping/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/11_exceptions_part1_groundwork/src/synchronization.rs b/11_exceptions_part1_groundwork/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/11_exceptions_part1_groundwork/src/synchronization.rs +++ b/11_exceptions_part1_groundwork/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/12_integrated_testing/kernel/src/synchronization.rs b/12_integrated_testing/kernel/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/12_integrated_testing/kernel/src/synchronization.rs +++ b/12_integrated_testing/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; diff --git a/13_exceptions_part2_peripheral_IRQs/README.md b/13_exceptions_part2_peripheral_IRQs/README.md index 634686d6..9a5b7b4f 100644 --- a/13_exceptions_part2_peripheral_IRQs/README.md +++ b/13_exceptions_part2_peripheral_IRQs/README.md @@ -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 @@ -28,6 +28,21 @@ /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -2617,10 +2617,10 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part + type Data; + + /// Grants temporary mutable access to the encapsulated data. -+ fn write(&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. -+ fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 @@ // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -2695,7 +2695,7 @@ diff -uNr 12_integrated_testing/kernel/src/synchronization.rs 13_exceptions_part +impl interface::ReadWriteEx for InitStateLock { + type Data = T; + -+ fn write(&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!( + state::state_manager().is_init(), + "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) } + -+ fn read(&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() }; + + f(data) diff --git a/13_exceptions_part2_peripheral_IRQs/kernel/src/synchronization.rs b/13_exceptions_part2_peripheral_IRQs/kernel/src/synchronization.rs index 4b4c4c3f..ab2b86e6 100644 --- a/13_exceptions_part2_peripheral_IRQs/kernel/src/synchronization.rs +++ b/13_exceptions_part2_peripheral_IRQs/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -38,10 +38,10 @@ pub mod interface { type Data; /// Grants temporary mutable access to the encapsulated data. - fn write(&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. - fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -118,7 +118,7 @@ impl interface::Mutex for IRQSafeNullLock { impl interface::ReadWriteEx for InitStateLock { type Data = T; - fn write(&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!( state::state_manager().is_init(), "InitStateLock::write called after kernel init phase" @@ -133,7 +133,7 @@ impl interface::ReadWriteEx for InitStateLock { f(data) } - fn read(&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() }; f(data) diff --git a/14_virtual_mem_part2_mmio_remap/kernel/src/synchronization.rs b/14_virtual_mem_part2_mmio_remap/kernel/src/synchronization.rs index 4b4c4c3f..ab2b86e6 100644 --- a/14_virtual_mem_part2_mmio_remap/kernel/src/synchronization.rs +++ b/14_virtual_mem_part2_mmio_remap/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -38,10 +38,10 @@ pub mod interface { type Data; /// Grants temporary mutable access to the encapsulated data. - fn write(&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. - fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -118,7 +118,7 @@ impl interface::Mutex for IRQSafeNullLock { impl interface::ReadWriteEx for InitStateLock { type Data = T; - fn write(&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!( state::state_manager().is_init(), "InitStateLock::write called after kernel init phase" @@ -133,7 +133,7 @@ impl interface::ReadWriteEx for InitStateLock { f(data) } - fn read(&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() }; f(data) diff --git a/15_virtual_mem_part3_precomputed_tables/kernel/src/synchronization.rs b/15_virtual_mem_part3_precomputed_tables/kernel/src/synchronization.rs index 4b4c4c3f..ab2b86e6 100644 --- a/15_virtual_mem_part3_precomputed_tables/kernel/src/synchronization.rs +++ b/15_virtual_mem_part3_precomputed_tables/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -38,10 +38,10 @@ pub mod interface { type Data; /// Grants temporary mutable access to the encapsulated data. - fn write(&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. - fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -118,7 +118,7 @@ impl interface::Mutex for IRQSafeNullLock { impl interface::ReadWriteEx for InitStateLock { type Data = T; - fn write(&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!( state::state_manager().is_init(), "InitStateLock::write called after kernel init phase" @@ -133,7 +133,7 @@ impl interface::ReadWriteEx for InitStateLock { f(data) } - fn read(&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() }; f(data) diff --git a/16_virtual_mem_part4_higher_half_kernel/kernel/src/synchronization.rs b/16_virtual_mem_part4_higher_half_kernel/kernel/src/synchronization.rs index 4b4c4c3f..ab2b86e6 100644 --- a/16_virtual_mem_part4_higher_half_kernel/kernel/src/synchronization.rs +++ b/16_virtual_mem_part4_higher_half_kernel/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -38,10 +38,10 @@ pub mod interface { type Data; /// Grants temporary mutable access to the encapsulated data. - fn write(&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. - fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -118,7 +118,7 @@ impl interface::Mutex for IRQSafeNullLock { impl interface::ReadWriteEx for InitStateLock { type Data = T; - fn write(&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!( state::state_manager().is_init(), "InitStateLock::write called after kernel init phase" @@ -133,7 +133,7 @@ impl interface::ReadWriteEx for InitStateLock { f(data) } - fn read(&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() }; f(data) diff --git a/17_kernel_symbols/kernel/src/synchronization.rs b/17_kernel_symbols/kernel/src/synchronization.rs index 4b4c4c3f..ab2b86e6 100644 --- a/17_kernel_symbols/kernel/src/synchronization.rs +++ b/17_kernel_symbols/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -38,10 +38,10 @@ pub mod interface { type Data; /// Grants temporary mutable access to the encapsulated data. - fn write(&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. - fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -118,7 +118,7 @@ impl interface::Mutex for IRQSafeNullLock { impl interface::ReadWriteEx for InitStateLock { type Data = T; - fn write(&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!( state::state_manager().is_init(), "InitStateLock::write called after kernel init phase" @@ -133,7 +133,7 @@ impl interface::ReadWriteEx for InitStateLock { f(data) } - fn read(&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() }; f(data) diff --git a/18_backtrace/kernel/src/synchronization.rs b/18_backtrace/kernel/src/synchronization.rs index 4b4c4c3f..ab2b86e6 100644 --- a/18_backtrace/kernel/src/synchronization.rs +++ b/18_backtrace/kernel/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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. @@ -38,10 +38,10 @@ pub mod interface { type Data; /// Grants temporary mutable access to the encapsulated data. - fn write(&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. - fn read(&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 interface::Mutex for IRQSafeNullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() }; @@ -118,7 +118,7 @@ impl interface::Mutex for IRQSafeNullLock { impl interface::ReadWriteEx for InitStateLock { type Data = T; - fn write(&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!( state::state_manager().is_init(), "InitStateLock::write called after kernel init phase" @@ -133,7 +133,7 @@ impl interface::ReadWriteEx for InitStateLock { f(data) } - fn read(&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() }; f(data) diff --git a/X1_JTAG_boot/src/synchronization.rs b/X1_JTAG_boot/src/synchronization.rs index d5653a19..d3937b0d 100644 --- a/X1_JTAG_boot/src/synchronization.rs +++ b/X1_JTAG_boot/src/synchronization.rs @@ -26,7 +26,7 @@ pub mod interface { type Data; /// Locks the mutex and grants the closure temporary mutable access to the wrapped data. - fn lock(&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 NullLock { impl interface::Mutex for NullLock { type Data = T; - fn lock(&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 // mutable reference will ever only be given out once at a time. let data = unsafe { &mut *self.data.get() };