forked from MightyPork/crsn
more docs, fixes, examples
This commit is contained in:
@@ -613,7 +613,7 @@ mod test {
|
||||
global_regs: [0; REG_COUNT],
|
||||
ext_data: Default::default(),
|
||||
cr_deadline: None,
|
||||
critical_section: false,
|
||||
critical_section: 0,
|
||||
},
|
||||
const_eval_ti: ti.clone(),
|
||||
parsing_expr: false,
|
||||
|
||||
@@ -230,7 +230,9 @@ impl RunThread {
|
||||
// Do switch
|
||||
let old = mem::replace(&mut self.state.cr, cr);
|
||||
self.state.parked.push_back(old);
|
||||
self.state.cr_deadline = Some(now + *self.info.scheduler_interval.read());
|
||||
|
||||
self.state.start_task_switching();
|
||||
|
||||
} else if let Some(due) = closest_due {
|
||||
let time = due.saturating_duration_since(now);
|
||||
trace!("No thread to switch to, sleep {:?}", time);
|
||||
@@ -248,7 +250,7 @@ impl RunThread {
|
||||
|
||||
if n_alive == 0 {
|
||||
trace!("Stop task switching, no parked threads are alive");
|
||||
self.state.cr_deadline = None;
|
||||
self.state.stop_task_switching(); // This should improve performance in single-threaded mode
|
||||
}
|
||||
|
||||
match self.state.cr.cr_state {
|
||||
|
||||
@@ -12,7 +12,7 @@ use nudge::{likely};
|
||||
use crate::asm::instr::cond::Flag;
|
||||
use std::fmt::{Debug, Formatter};
|
||||
use std::fmt;
|
||||
use std::time::Instant;
|
||||
use std::time::{Instant, Duration};
|
||||
|
||||
pub struct RunState {
|
||||
pub thread_info: Arc<ThreadInfo>,
|
||||
@@ -95,10 +95,24 @@ impl RunState {
|
||||
});
|
||||
if self.cr_deadline.is_none() {
|
||||
// start context switching
|
||||
self.cr_deadline = Some(Instant::now() + *self.thread_info.scheduler_interval.read());
|
||||
self.start_task_switching();
|
||||
}
|
||||
handle
|
||||
}
|
||||
|
||||
pub(crate) fn start_task_switching(&mut self) {
|
||||
let ival = *self.thread_info.scheduler_interval.read();
|
||||
if ival > Duration::default() {
|
||||
self.cr_deadline = Some(Instant::now() + ival);
|
||||
} else {
|
||||
// Disabled
|
||||
self.cr_deadline = None;
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn stop_task_switching(&mut self) {
|
||||
self.cr_deadline = None;
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for RunState {
|
||||
|
||||
Reference in New Issue
Block a user