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