|
|
|
@ -1,14 +1,16 @@ |
|
|
|
|
use std::sync::Arc; |
|
|
|
|
use std::sync::atomic::{AtomicU64, Ordering}; |
|
|
|
|
use std::sync::atomic::AtomicU64; |
|
|
|
|
use std::thread::JoinHandle; |
|
|
|
|
use std::time::Duration; |
|
|
|
|
|
|
|
|
|
use crate::asm::data::literal::{Addr, Value}; |
|
|
|
|
pub use info::ThreadInfo; |
|
|
|
|
pub use state::RunState; |
|
|
|
|
|
|
|
|
|
use crate::asm::data::literal::Addr; |
|
|
|
|
use crate::module::EvalRes; |
|
|
|
|
use crate::runtime::fault::Fault; |
|
|
|
|
use crate::runtime::frame::StackFrame; |
|
|
|
|
use crate::runtime::program::Program; |
|
|
|
|
use crate::runtime::run_thread::info::{UNIQ_BASE}; |
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd)] |
|
|
|
|
pub struct ThreadToken(pub u32); |
|
|
|
@ -20,27 +22,17 @@ pub struct RunThread { |
|
|
|
|
|
|
|
|
|
pub mod info; |
|
|
|
|
pub mod state; |
|
|
|
|
pub use info::ThreadInfo; |
|
|
|
|
pub use state::RunState; |
|
|
|
|
|
|
|
|
|
pub fn new_uniq() -> &'static AtomicU64 { |
|
|
|
|
let uniq = AtomicU64::new(info::UNIQ_BASE); |
|
|
|
|
Box::leak(Box::new(uniq)) |
|
|
|
|
pub fn new_uniq() -> Arc<AtomicU64> { |
|
|
|
|
Arc::new(AtomicU64::new(info::UNIQ_BASE)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl RunThread { |
|
|
|
|
pub fn new(id: ThreadToken, uniq: Option<&'static AtomicU64>, program: Arc<Program>, pc: Addr, args: &[u64]) -> Self { |
|
|
|
|
let uniq = if let Some(u) = uniq { |
|
|
|
|
u |
|
|
|
|
} else { |
|
|
|
|
let u = AtomicU64::new(UNIQ_BASE); |
|
|
|
|
Box::leak(Box::new(u)) as &AtomicU64 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
pub fn new(id: ThreadToken, uniq: Option<Arc<AtomicU64>>, program: Arc<Program>, pc: Addr, args: &[u64]) -> Self { |
|
|
|
|
Self { |
|
|
|
|
info: ThreadInfo { |
|
|
|
|
id, |
|
|
|
|
uniq, |
|
|
|
|
uniq: uniq.unwrap_or_else(new_uniq), |
|
|
|
|
program, |
|
|
|
|
cycle_time: Duration::default(), |
|
|
|
|
}, |
|
|
|
|