//! Burritos stores a data structure associating object ids with //! their references. The ObjAddr struct //! allows to maintain this data structure. use std::collections::HashMap; pub trait SynchObj { } /// Brief Definition of object identifiers: /// /// The struct stores the list of created objects (Semaphore, Lock, ...) and for each of them /// associates an object identifier than can be passed to subsequent /// system calls on the object. /// /// A method allows to detect of an object corresponding to a given /// identifier exists; this is used to check the parameters of system /// calls. struct ObjAddr<'a> { last_id: i32, map: HashMap } impl<'a> ObjAddr<'a> { /// Initializes and returns a ObjAddr struct pub fn init() -> Self { Self { last_id: 3, map: HashMap::::new() } } /// Adds the **obj** SynchObj to self pub fn add_object(&mut self, obj: &'a dyn SynchObj) -> i32 { self.last_id = self.last_id + 1; self.map.insert(self.last_id, obj); self.last_id } /// Searches for an object of id **id** in self pub fn search_object(&self, id: i32) -> Option<&& dyn SynchObj> { self.map.get(&id) } /// Removes the object of id **id** from self if it exists pub fn remove_object_from_key(&mut self, id: i32) { self.map.remove(&id); } }