|
|
@ -2,12 +2,12 @@ use std::iter::repeat_with; |
|
|
|
use std::sync::atomic::{AtomicBool, Ordering}; |
|
|
|
use std::sync::atomic::{AtomicBool, Ordering}; |
|
|
|
use tracing::debug; |
|
|
|
use tracing::debug; |
|
|
|
|
|
|
|
|
|
|
|
pub type SectionId = u32; |
|
|
|
pub type SecId = u32; |
|
|
|
|
|
|
|
|
|
|
|
pub trait SectionInterface: Send { |
|
|
|
pub trait SectionInterface: Send { |
|
|
|
fn num_sections(&self) -> SectionId; |
|
|
|
fn num_sections(&self) -> SecId; |
|
|
|
fn set_section_state(&self, id: SectionId, running: bool); |
|
|
|
fn set_section_state(&self, id: SecId, running: bool); |
|
|
|
fn get_section_state(&self, id: SectionId) -> bool; |
|
|
|
fn get_section_state(&self, id: SecId) -> bool; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub struct MockSectionInterface { |
|
|
|
pub struct MockSectionInterface { |
|
|
@ -16,7 +16,7 @@ pub struct MockSectionInterface { |
|
|
|
|
|
|
|
|
|
|
|
impl MockSectionInterface { |
|
|
|
impl MockSectionInterface { |
|
|
|
#[allow(dead_code)] |
|
|
|
#[allow(dead_code)] |
|
|
|
pub fn new(num_sections: SectionId) -> Self { |
|
|
|
pub fn new(num_sections: SecId) -> Self { |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
states: repeat_with(|| AtomicBool::new(false)) |
|
|
|
states: repeat_with(|| AtomicBool::new(false)) |
|
|
|
.take(num_sections as usize) |
|
|
|
.take(num_sections as usize) |
|
|
@ -26,14 +26,14 @@ impl MockSectionInterface { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl SectionInterface for MockSectionInterface { |
|
|
|
impl SectionInterface for MockSectionInterface { |
|
|
|
fn num_sections(&self) -> SectionId { |
|
|
|
fn num_sections(&self) -> SecId { |
|
|
|
self.states.len() as SectionId |
|
|
|
self.states.len() as SecId |
|
|
|
} |
|
|
|
} |
|
|
|
fn set_section_state(&self, id: SectionId, running: bool) { |
|
|
|
fn set_section_state(&self, id: SecId, running: bool) { |
|
|
|
debug!(id, running, "setting section"); |
|
|
|
debug!(id, running, "setting section"); |
|
|
|
self.states[id as usize].store(running, Ordering::SeqCst); |
|
|
|
self.states[id as usize].store(running, Ordering::SeqCst); |
|
|
|
} |
|
|
|
} |
|
|
|
fn get_section_state(&self, id: SectionId) -> bool { |
|
|
|
fn get_section_state(&self, id: SecId) -> bool { |
|
|
|
self.states[id as usize].load(Ordering::SeqCst) |
|
|
|
self.states[id as usize].load(Ordering::SeqCst) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|