Added sc_v call
This commit is contained in:
parent
afce2c66c9
commit
729eba656c
@ -1,8 +1,10 @@
|
|||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
|
use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}};
|
||||||
|
|
||||||
use super::{system::System, thread::Thread};
|
use super::{system::System, thread::Thread, synch::Semaphore};
|
||||||
|
|
||||||
|
type Error = String;
|
||||||
|
|
||||||
/// The halt system call. Stops Burritos.
|
/// The halt system call. Stops Burritos.
|
||||||
pub const SC_SHUTDOWN: u8 = 0;
|
pub const SC_SHUTDOWN: u8 = 0;
|
||||||
@ -202,7 +204,7 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
|
|||||||
SC_YIELD => todo!(),
|
SC_YIELD => todo!(),
|
||||||
SC_PERROR => todo!(),
|
SC_PERROR => todo!(),
|
||||||
SC_P => todo!(),
|
SC_P => todo!(),
|
||||||
SC_V => todo!(),
|
SC_V => sc_v(machine, system),
|
||||||
SC_SEM_CREATE => {
|
SC_SEM_CREATE => {
|
||||||
let addr_name = machine.read_int_register(10) as usize;
|
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);
|
||||||
@ -238,6 +240,14 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn sc_v(machine: &mut Machine, system: &mut System) -> Result<(), Error>{
|
||||||
|
let id_sema = machine.int_reg.get_reg(10);
|
||||||
|
match system.get_obj_addrs().search_semaphore(id_sema) {
|
||||||
|
Some(sema) => { sema.v(machine, system.get_thread_manager()); Ok(()) },
|
||||||
|
None => Err(format!("Couldn't find semaphore {}", id_sema))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_length_param(addr: usize, machine: & Machine) -> usize{
|
fn get_length_param(addr: usize, machine: & Machine) -> usize{
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
let mut c = 1;
|
let mut c = 1;
|
||||||
|
@ -4,12 +4,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
/// This trait allows ObjAddr to hold references to Multiple kinds of structs
|
use crate::kernel::synch::{ Semaphore, Lock };
|
||||||
///
|
|
||||||
/// - Lock
|
|
||||||
/// - Condition
|
|
||||||
/// - Sémaphore
|
|
||||||
pub trait SynchObj { }
|
|
||||||
|
|
||||||
/// Brief Definition of object identifiers:
|
/// Brief Definition of object identifiers:
|
||||||
///
|
///
|
||||||
@ -20,36 +15,55 @@ pub trait SynchObj { }
|
|||||||
/// A method allows to detect of an object corresponding to a given
|
/// A method allows to detect of an object corresponding to a given
|
||||||
/// identifier exists; this is used to check the parameters of system
|
/// identifier exists; this is used to check the parameters of system
|
||||||
/// calls.
|
/// calls.
|
||||||
pub struct ObjAddr<'a> {
|
pub struct ObjAddr {
|
||||||
last_id: i32,
|
last_id: i32,
|
||||||
map: HashMap<i32, &'a dyn SynchObj>
|
semaphores: HashMap<i32, Semaphore>,
|
||||||
|
locks: HashMap<i32, Lock>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ObjAddr<'a> {
|
impl ObjAddr {
|
||||||
|
|
||||||
/// Initializes and returns a ObjAddr struct
|
/// Initializes and returns a ObjAddr struct
|
||||||
pub fn init() -> Self {
|
pub fn init() -> Self {
|
||||||
Self {
|
Self {
|
||||||
last_id: 3,
|
last_id: 3,
|
||||||
map: HashMap::<i32, &dyn SynchObj>::new()
|
semaphores: HashMap::<i32, Semaphore>::new(),
|
||||||
|
locks: HashMap::<i32, Lock>::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds the **obj** SynchObj to self
|
/// Adds the **obj** Semaphore to self
|
||||||
pub fn add_object(&mut self, obj: &'a dyn SynchObj) -> i32 {
|
pub fn add_semaphore(&mut self, obj: Semaphore) -> i32 {
|
||||||
self.last_id = self.last_id + 1;
|
self.last_id = self.last_id + 1;
|
||||||
self.map.insert(self.last_id, obj);
|
self.semaphores.insert(self.last_id, obj);
|
||||||
self.last_id
|
self.last_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Searches for an object of id **id** in self
|
/// Adds the **obj** Lock to self
|
||||||
pub fn search_object(&self, id: i32) -> Option<&& dyn SynchObj> {
|
pub fn add_lock(&mut self, obj: Lock) -> i32 {
|
||||||
self.map.get(&id)
|
self.last_id = self.last_id + 1;
|
||||||
|
self.locks.insert(self.last_id, obj);
|
||||||
|
self.last_id
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Searches for a semaphore of id **id** in self
|
||||||
|
pub fn search_semaphore(&self, id: i32) -> Option<&mut Semaphore> {
|
||||||
|
self.semaphores.get(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Searches for a lock of id **id** in self
|
||||||
|
pub fn search_lock(&self, id:i32) -> Option<&mut Lock> {
|
||||||
|
self.locks.get(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes the object of id **id** from self if it exists
|
/// Removes the object of id **id** from self if it exists
|
||||||
pub fn remove_object_from_key(&mut self, id: i32) {
|
pub fn remove_semaphore(&mut self, id: i32) {
|
||||||
self.map.remove(&id);
|
self.semaphores.remove(&id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn remove_semaphore(&mut self, id:i32) {
|
||||||
|
self.locks.remove(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user