From 6aa0fb450f417ce899b43f4539eb226b391a0f2e Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 8 Apr 2021 18:25:09 +0200 Subject: Goodbye static mut --- macros/src/codegen/module.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'macros/src/codegen/module.rs') diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 50146c0..8c148cc 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -245,14 +245,15 @@ pub fn codegen( let input = #tupled; unsafe { - if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) { + if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.get_mut_unchecked().dequeue()) { #app_path::#inputs + .get_mut_unchecked() .get_unchecked_mut(usize::from(index)) .as_mut_ptr() .write(input); rtic::export::interrupt::free(|_| { - #app_path::#rq.enqueue_unchecked((#app_path::#t::#name, index)); + #app_path::#rq.get_mut_unchecked().enqueue_unchecked((#app_path::#t::#name, index)); }); rtic::pend(#device::#enum_::#interrupt); @@ -304,6 +305,9 @@ pub fn codegen( let user_imports = &app.user_imports; let tq_marker = util::mark_internal_ident(&util::timer_queue_marker_ident()); + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + // items.push(quote!(#[doc = #doc])); + items.push(quote!( /// Holds methods related to this monotonic pub mod #m { @@ -325,12 +329,16 @@ pub fn codegen( impl SpawnHandle { pub fn cancel(self) -> Result<#ty, ()> { rtic::export::interrupt::free(|_| unsafe { - let tq = &mut *#app_path::#tq.as_mut_ptr(); + let tq = &mut *#app_path::#tq.get_mut_unchecked().as_mut_ptr(); if let Some((_task, index)) = tq.cancel_marker(self.marker) { // Get the message - let msg = #app_path::#inputs.get_unchecked(usize::from(index)).as_ptr().read(); + let msg = #app_path::#inputs + .get_unchecked() + .get_unchecked(usize::from(index)) + .as_ptr() + .read(); // Return the index to the free queue - #app_path::#fq.split().0.enqueue_unchecked(index); + #app_path::#fq.get_mut_unchecked().split().0.enqueue_unchecked(index); Ok(msg) } else { @@ -350,10 +358,10 @@ pub fn codegen( pub fn reschedule_at(self, instant: rtic::time::Instant<#app_path::#mono_type>) -> Result { rtic::export::interrupt::free(|_| unsafe { - let marker = #tq_marker; - #tq_marker = #tq_marker.wrapping_add(1); + let marker = *#tq_marker.get_mut_unchecked(); + *#tq_marker.get_mut_unchecked() = #tq_marker.get_mut_unchecked().wrapping_add(1); - let tq = &mut *#app_path::#tq.as_mut_ptr(); + let tq = &mut *#app_path::#tq.get_mut_unchecked().as_mut_ptr(); tq.update_marker(self.marker, marker, instant, || #pend).map(|_| SpawnHandle { marker }) }) @@ -373,7 +381,7 @@ pub fn codegen( D::T: Into<<#app_path::#mono_type as rtic::time::Clock>::T>, { - let instant = if rtic::export::interrupt::free(|_| unsafe { #app_path::#m_ident.is_none() }) { + let instant = if rtic::export::interrupt::free(|_| unsafe { #app_path::#m_ident.get_mut_unchecked().is_none() }) { rtic::time::Instant::new(0) } else { #app_path::monotonics::#m::now() @@ -390,19 +398,21 @@ pub fn codegen( ) -> Result { unsafe { let input = #tupled; - if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) { + if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.get_mut_unchecked().dequeue()) { #app_path::#inputs + .get_mut_unchecked() .get_unchecked_mut(usize::from(index)) .as_mut_ptr() .write(input); #app_path::#instants + .get_mut_unchecked() .get_unchecked_mut(usize::from(index)) .as_mut_ptr() .write(instant); rtic::export::interrupt::free(|_| { - let marker = #tq_marker; + let marker = *#tq_marker.get_mut_unchecked(); let nr = rtic::export::NotReady { instant, index, @@ -410,15 +420,15 @@ pub fn codegen( marker, }; - #tq_marker = #tq_marker.wrapping_add(1); + *#tq_marker.get_mut_unchecked() = #tq_marker.get_mut_unchecked().wrapping_add(1); - let tq = unsafe { &mut *#app_path::#tq.as_mut_ptr() }; + let tq = &mut *#app_path::#tq.get_mut_unchecked().as_mut_ptr(); tq.enqueue_unchecked( nr, || #enable_interrupt, || #pend, - #app_path::#m_ident.as_mut()); + #app_path::#m_ident.get_mut_unchecked().as_mut()); Ok(SpawnHandle { marker }) }) -- cgit v1.2.3 From 50f26e78eda57cb1f9f815aa93b357c2cd1a0205 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 22 Apr 2021 18:38:42 +0200 Subject: Keep comments --- macros/src/codegen/module.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'macros/src/codegen/module.rs') diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 8c148cc..9bcc8f6 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -305,6 +305,7 @@ pub fn codegen( let user_imports = &app.user_imports; let tq_marker = util::mark_internal_ident(&util::timer_queue_marker_ident()); + // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); // items.push(quote!(#[doc = #doc])); -- cgit v1.2.3