remove mut bound for seq counter impl
This commit is contained in:
parent
328a060e9c
commit
245388fafa
@ -340,7 +340,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<TcStateAccepted>, VerificationErrorWithToken<E, TcStateNone>>
|
||||
{
|
||||
@ -371,7 +371,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateNone>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateNone>> {
|
||||
let tm = self
|
||||
@ -399,7 +399,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<VerificationToken<TcStateStarted>, VerificationErrorWithToken<E, TcStateAccepted>>
|
||||
{
|
||||
@ -432,7 +432,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateAccepted>> {
|
||||
let tm = self
|
||||
@ -460,7 +460,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: &VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
step: impl EcssEnumeration,
|
||||
) -> Result<(), EcssTmError<E>> {
|
||||
@ -486,7 +486,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
params: FailParamsWithStep,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
let tm = self
|
||||
@ -515,7 +515,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
time_stamp: &[u8],
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
let tm = self
|
||||
@ -544,7 +544,7 @@ impl VerificationReporterCore {
|
||||
buf: &mut [u8],
|
||||
token: VerificationToken<TcStateStarted>,
|
||||
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
|
||||
seq_counter: &mut (impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||
params: FailParams,
|
||||
) -> Result<(), VerificationErrorWithToken<E, TcStateStarted>> {
|
||||
let tm = self
|
||||
|
@ -1,17 +1,35 @@
|
||||
use core::cell::Cell;
|
||||
use core::sync::atomic::{AtomicU16, Ordering};
|
||||
#[cfg(feature = "alloc")]
|
||||
use dyn_clone::DynClone;
|
||||
#[cfg(feature = "std")]
|
||||
pub use stdmod::*;
|
||||
|
||||
/// Core trait for objects which can provide a sequence count.
|
||||
///
|
||||
/// The core functions are not mutable on purpose to allow easier usage with
|
||||
/// static structs when using the interior mutability pattern. This can be achieved by using
|
||||
/// [Cell], [RefCell] or atomic types.
|
||||
pub trait SequenceCountProviderCore<Raw> {
|
||||
fn get(&self) -> Raw;
|
||||
fn increment(&mut self);
|
||||
fn get_and_increment(&mut self) -> Raw {
|
||||
|
||||
fn increment(&self);
|
||||
|
||||
// TODO: Maybe remove this?
|
||||
fn increment_mut(&mut self) {
|
||||
self.increment();
|
||||
}
|
||||
|
||||
fn get_and_increment(&self) -> Raw {
|
||||
let val = self.get();
|
||||
self.increment();
|
||||
val
|
||||
}
|
||||
|
||||
// TODO: Maybe remove this?
|
||||
fn get_and_increment_mut(&mut self) -> Raw {
|
||||
self.get_and_increment()
|
||||
}
|
||||
}
|
||||
|
||||
/// Extension trait which allows cloning a sequence count provider after it was turned into
|
||||
@ -25,25 +43,30 @@ impl<T, Raw> SequenceCountProvider<Raw> for T where T: SequenceCountProviderCore
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
pub struct SeqCountProviderSimple {
|
||||
seq_count: u16,
|
||||
seq_count: Cell<u16>,
|
||||
}
|
||||
|
||||
impl SequenceCountProviderCore<u16> for SeqCountProviderSimple {
|
||||
fn get(&self) -> u16 {
|
||||
self.seq_count
|
||||
self.seq_count.get()
|
||||
}
|
||||
|
||||
fn increment(&mut self) {
|
||||
if self.seq_count == u16::MAX {
|
||||
self.seq_count = 0;
|
||||
return;
|
||||
fn increment(&self) {
|
||||
self.get_and_increment();
|
||||
}
|
||||
|
||||
fn get_and_increment(&self) -> u16 {
|
||||
let curr_count = self.seq_count.get();
|
||||
|
||||
if curr_count == u16::MAX {
|
||||
self.seq_count.set(0);
|
||||
} else {
|
||||
self.seq_count.set(curr_count + 1);
|
||||
}
|
||||
self.seq_count += 1;
|
||||
curr_count
|
||||
}
|
||||
}
|
||||
|
||||
use core::sync::atomic::{AtomicU16, Ordering};
|
||||
|
||||
pub struct SeqCountProviderAtomicRef {
|
||||
atomic: AtomicU16,
|
||||
ordering: Ordering,
|
||||
@ -51,7 +74,10 @@ pub struct SeqCountProviderAtomicRef {
|
||||
|
||||
impl SeqCountProviderAtomicRef {
|
||||
pub const fn new(ordering: Ordering) -> Self {
|
||||
Self { atomic: AtomicU16::new(0), ordering }
|
||||
Self {
|
||||
atomic: AtomicU16::new(0),
|
||||
ordering,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,11 +86,11 @@ impl SequenceCountProviderCore<u16> for SeqCountProviderAtomicRef {
|
||||
self.atomic.load(self.ordering)
|
||||
}
|
||||
|
||||
fn increment(&mut self) {
|
||||
fn increment(&self) {
|
||||
self.atomic.fetch_add(1, self.ordering);
|
||||
}
|
||||
|
||||
fn get_and_increment(&mut self) -> u16 {
|
||||
fn get_and_increment(&self) -> u16 {
|
||||
self.atomic.fetch_add(1, self.ordering)
|
||||
}
|
||||
}
|
||||
@ -75,20 +101,20 @@ pub mod stdmod {
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct SeqCountProviderSync {
|
||||
pub struct SeqCountProviderSyncClonable {
|
||||
seq_count: Arc<AtomicU16>,
|
||||
}
|
||||
|
||||
impl SequenceCountProviderCore<u16> for SeqCountProviderSync {
|
||||
impl SequenceCountProviderCore<u16> for SeqCountProviderSyncClonable {
|
||||
fn get(&self) -> u16 {
|
||||
self.seq_count.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn increment(&mut self) {
|
||||
fn increment(&self) {
|
||||
self.seq_count.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
fn get_and_increment(&mut self) -> u16 {
|
||||
fn get_and_increment(&self) -> u16 {
|
||||
self.seq_count.fetch_add(1, Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ pub mod crossbeam_test {
|
||||
CrossbeamVerifSender, FailParams, RequestId, VerificationReporterCfg,
|
||||
VerificationReporterWithSender,
|
||||
};
|
||||
use satrs_core::seq_count::SeqCountProviderSync;
|
||||
use satrs_core::seq_count::SeqCountProviderSyncClonable;
|
||||
use spacepackets::ecss::{EcssEnumU16, EcssEnumU8, PusPacket};
|
||||
use spacepackets::tc::{PusTc, PusTcSecondaryHeader};
|
||||
use spacepackets::tm::PusTm;
|
||||
@ -34,7 +34,7 @@ pub mod crossbeam_test {
|
||||
// each reporter have an own sequence count provider.
|
||||
let cfg = VerificationReporterCfg::new(
|
||||
TEST_APID,
|
||||
Box::new(SeqCountProviderSync::default()),
|
||||
Box::new(SeqCountProviderSyncClonable::default()),
|
||||
1,
|
||||
2,
|
||||
8,
|
||||
|
Loading…
Reference in New Issue
Block a user