cyccnt::Instant: simplify the Send / Sync impl

originally the type was made `!Send` because it loses its meaning when
send from one core to another but that was an incorrect use of the `Send`
bound (the send operation makes the value incorrect but that doesn't cause
memory unsafety on its own). So later the type was (explicitly) made `Send`
again resulting in a convoluted implementation -- this commit simplifies things.
This commit is contained in:
Jorge Aparicio 2019-10-15 19:12:05 -05:00
parent 6207008884
commit a458a07031

View file

@ -3,9 +3,7 @@
use core::{ use core::{
cmp::Ordering, cmp::Ordering,
convert::{Infallible, TryInto}, convert::{Infallible, TryInto},
fmt, fmt, ops,
marker::PhantomData,
ops,
}; };
use cortex_m::peripheral::DWT; use cortex_m::peripheral::DWT;
@ -28,19 +26,13 @@ use crate::Fraction;
#[derive(Clone, Copy, Eq, PartialEq)] #[derive(Clone, Copy, Eq, PartialEq)]
pub struct Instant { pub struct Instant {
inner: i32, inner: i32,
_not_send_or_sync: PhantomData<*mut ()>,
} }
unsafe impl Sync for Instant {}
unsafe impl Send for Instant {}
impl Instant { impl Instant {
/// Returns an instant corresponding to "now" /// Returns an instant corresponding to "now"
pub fn now() -> Self { pub fn now() -> Self {
Instant { Instant {
inner: DWT::get_cycle_count() as i32, inner: DWT::get_cycle_count() as i32,
_not_send_or_sync: PhantomData,
} }
} }
@ -222,9 +214,6 @@ impl crate::Monotonic for CYCCNT {
} }
fn zero() -> Instant { fn zero() -> Instant {
Instant { Instant { inner: 0 }
inner: 0,
_not_send_or_sync: PhantomData,
}
} }
} }