Use Vec to replace array in ProcessManager.

toolchain_update
WangRunji 6 years ago
parent 182c595a20
commit 74facd8e87

@ -19,7 +19,7 @@ env:
install:
- if [ $ARCH = riscv32 ]; then
export FILE="riscv64-unknown-elf-gcc-2018.07.0-x86_64-linux-ubuntu14";
export FILE="riscv64-unknown-elf-gcc-20180928-x86_64-linux-ubuntu14";
wget https://static.dev.sifive.com/dev-tools/$FILE.tar.gz;
tar xf $FILE.tar.gz;
export PATH=$PATH:$PWD/$FILE/bin;

@ -3,6 +3,7 @@
#![feature(const_fn)]
#![feature(linkage)]
#![feature(nll)]
#![feature(vec_resize_default)]
extern crate alloc;
#[macro_use]

@ -15,7 +15,6 @@ struct Process {
pub type Pid = usize;
type ExitCode = usize;
const MAX_PROC_NUM: usize = 32;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Status {
@ -36,25 +35,33 @@ pub trait Context {
}
pub struct ProcessManager {
procs: [Mutex<Option<Process>>; MAX_PROC_NUM],
procs: Vec<Mutex<Option<Process>>>,
scheduler: Mutex<Box<Scheduler>>,
wait_queue: [Mutex<Vec<Pid>>; MAX_PROC_NUM],
wait_queue: Vec<Mutex<Vec<Pid>>>,
event_hub: Mutex<EventHub<Event>>,
}
impl ProcessManager {
pub fn new(scheduler: Box<Scheduler>) -> Self {
pub fn new(scheduler: Box<Scheduler>, max_proc_num: usize) -> Self {
ProcessManager {
procs: Default::default(),
procs: {
let mut vec = Vec::new();
vec.resize_default(max_proc_num);
vec
},
scheduler: Mutex::new(scheduler),
wait_queue: Default::default(),
wait_queue: {
let mut vec = Vec::new();
vec.resize_default(max_proc_num);
vec
},
event_hub: Mutex::new(EventHub::new()),
}
}
fn alloc_pid(&self) -> Pid {
for i in 0..MAX_PROC_NUM {
if self.procs[i].lock().is_none() {
for (i, proc) in self.procs.iter().enumerate() {
if proc.lock().is_none() {
return i;
}
}
@ -64,7 +71,7 @@ impl ProcessManager {
/// Add a new process
pub fn add(&self, context: Box<Context>) -> Pid {
let pid = self.alloc_pid();
*self.procs[pid].lock() = Some(Process {
*(&self.procs[pid]).lock() = Some(Process {
id: pid,
status: Status::Ready,
status_after_stop: Status::Ready,

@ -1,19 +1,16 @@
use spin::Once;
use sync::{SpinNoIrqLock, Mutex, MutexGuard, SpinNoIrq};
use spin::Mutex;
pub use self::context::ContextImpl;
pub use ucore_process::*;
use alloc::boxed::Box;
use consts::MAX_CPU_NUM;
use consts::{MAX_CPU_NUM, MAX_PROCESS_NUM};
use arch::cpu;
use alloc::sync::Arc;
use alloc::vec::Vec;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
mod context;
pub fn init() {
// NOTE: max_time_slice <= 5 to ensure 'priority' test pass
let scheduler = Box::new(scheduler::RRScheduler::new(5));
let manager = Arc::new(ProcessManager::new(scheduler));
let manager = Arc::new(ProcessManager::new(scheduler, MAX_PROCESS_NUM));
extern fn idle(_arg: usize) -> ! {
loop { cpu::halt(); }

Loading…
Cancel
Save