add new semaphore to obj_addrs in sc_sem_create

This commit is contained in:
Samy Solhi 2023-04-12 22:54:40 +02:00
parent 35736821c0
commit 19356a36d9

View File

@ -1,6 +1,7 @@
use std::{cell::RefCell, rc::Rc};
use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}};
use crate::kernel::synch::Semaphore;
use super::{system::System, thread::Thread};
@ -172,7 +173,7 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
SC_PERROR => todo!(),
SC_P => sc_p(machine, system),
SC_V => sc_v(machine, system),
SC_SEM_CREATE => sc_sem_create(machine),
SC_SEM_CREATE => sc_sem_create(machine, system),
SC_SEM_DESTROY => todo!(),
SC_LOCK_CREATE => todo!(),
SC_LOCK_DESTROY => todo!(),
@ -206,14 +207,17 @@ fn sc_v(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Machine
system.get_thread_manager().sem_v(id_sema as i32, machine)
}
fn sc_sem_create(machine: &mut Machine) -> Result<MachineOk, MachineError> {
fn sc_sem_create(machine: &mut Machine, system: &mut System) -> Result<MachineOk, MachineError> {
let addr_name = machine.read_int_register(10) as usize;
let initial_count = machine.read_int_register(11);
let initial_count = machine.read_int_register(11) as i32;
let size = get_length_param(addr_name as usize, machine);
let _name = get_string_param(addr_name, size, machine);
match initial_count < 0 {
true => Err(format!("Initial_count < 0"))?,
false => Ok(MachineOk::Ok)
false => {
system.get_thread_manager().get_obj_addrs().add_semaphore(Semaphore::new(initial_count));
Ok(MachineOk::Ok)
}
}
}