From 19356a36d9d4e224fe94c06835d1357d2f7ada72 Mon Sep 17 00:00:00 2001 From: Samy Solhi Date: Wed, 12 Apr 2023 22:54:40 +0200 Subject: [PATCH] add new semaphore to obj_addrs in sc_sem_create --- src/kernel/exception.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index 67a2026..4009d8a 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -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 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 Result { +fn sc_sem_create(machine: &mut Machine, system: &mut System) -> Result { 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) + } } }