From 35736821c08c3a1604ca5db16be9258b495c1431 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 12 Apr 2023 15:32:46 +0200 Subject: [PATCH] lint: remove some warning --- src/kernel/exception.rs | 2 -- src/kernel/synch.rs | 5 +++++ src/kernel/system.rs | 9 --------- src/kernel/thread.rs | 20 ++------------------ src/kernel/thread_manager.rs | 6 +++--- src/main.rs | 1 + src/utility/list.rs | 2 +- src/utility/objaddr.rs | 4 ++-- 8 files changed, 14 insertions(+), 35 deletions(-) diff --git a/src/kernel/exception.rs b/src/kernel/exception.rs index cff65ca..67a2026 100644 --- a/src/kernel/exception.rs +++ b/src/kernel/exception.rs @@ -4,8 +4,6 @@ use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, Ma use super::{system::System, thread::Thread}; -type Error = String; - /// The halt system call. Stops Burritos. pub const SC_SHUTDOWN: u8 = 0; /// The exit system call diff --git a/src/kernel/synch.rs b/src/kernel/synch.rs index bd63803..9f8eb02 100644 --- a/src/kernel/synch.rs +++ b/src/kernel/synch.rs @@ -142,6 +142,7 @@ impl Lock { } /// Structure of a condition used for synchronisation +#[allow(unused)] // -> No enough time to implement it pub struct Condition{ /// The queue of threads waiting for execution @@ -155,6 +156,7 @@ impl Condition { /// /// ### Parameters /// - *thread_manager* Thread manager which managing threads + #[allow(unused)] pub fn new() -> Condition { Condition{ waiting_queue: List::default()} } @@ -165,6 +167,7 @@ impl Condition { /// ### Parameters /// - **current_thread** the current thread /// - **machine** the machine where threads are executed + #[allow(unused)] pub fn wait(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) { let old_status = machine.interrupt.set_status(InterruptOff); match thread_manager.get_g_current_thread() { @@ -186,6 +189,7 @@ impl Condition { /// ### Parameters /// - **machine** the machine where the code is executed /// - **scheduler** the scheduler which determine which thread to execute + #[allow(unused)] pub fn signal(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) { let old_status = machine.interrupt.set_status(InterruptOff); @@ -204,6 +208,7 @@ impl Condition { /// ### Parameters /// - **machine** the machine where the code is executed /// - **scheduler** the scheduler which determine which thread to execute + #[allow(unused)] pub fn broadcast(&mut self, machine: &mut Machine, thread_manager: &mut ThreadManager) { let old_status = machine.interrupt.set_status(InterruptOff); diff --git a/src/kernel/system.rs b/src/kernel/system.rs index 9305444..29c41b6 100644 --- a/src/kernel/system.rs +++ b/src/kernel/system.rs @@ -35,12 +35,3 @@ impl Default for System { } } -#[derive(PartialEq, Debug)] -pub enum ObjectType { - SemaphoreType, - LockType, - ConditionType, - FileType, - ThreadType, - InvalidType -} diff --git a/src/kernel/thread.rs b/src/kernel/thread.rs index 4e661c4..838a5de 100644 --- a/src/kernel/thread.rs +++ b/src/kernel/thread.rs @@ -1,6 +1,6 @@ use std::{rc::Rc, cell::RefCell}; -use super::{process::Process, system::ObjectType}; +use super::process::Process; use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}}; const STACK_FENCEPOST: u32 = 0xdeadbeef; @@ -27,7 +27,6 @@ pub struct Thread { pub process: Option>>, pub thread_context: ThreadContext, pub stack_pointer: i32, - object_type: ObjectType } impl Thread { @@ -44,7 +43,6 @@ impl Thread { pc: 0 }, stack_pointer: 0, - object_type: ObjectType::ThreadType, } } @@ -76,23 +74,10 @@ impl Thread { } -impl Drop for Thread { - - fn drop(&mut self) { - self.object_type = ObjectType::InvalidType; - // todo!(); - } - -} - -fn start_thread_execution() { - -} - #[cfg(test)] mod test { - use super::{Thread, ThreadContext, NUM_INT_REGS, NUM_FP_REGS, ObjectType}; + use super::{Thread, ThreadContext, NUM_INT_REGS, NUM_FP_REGS}; const DEFAULT_THREAD_NAME: &str = "test_thread"; /// This macro allows for getting a Thread for which we've ensured proper initial state @@ -110,7 +95,6 @@ mod test { pc: 0 }; x.stack_pointer = 0; - x.object_type = ObjectType::ThreadType; x } }; } diff --git a/src/kernel/thread_manager.rs b/src/kernel/thread_manager.rs index 38205a7..33e768b 100644 --- a/src/kernel/thread_manager.rs +++ b/src/kernel/thread_manager.rs @@ -2,7 +2,7 @@ use std::{rc::Rc, cell::{RefCell, Ref}}; use crate::{utility::{list::List, objaddr::ObjAddr}, simulator::{machine::{NUM_INT_REGS, NUM_FP_REGS, Machine}, interrupt::InterruptStatus, error::{MachineOk, MachineError}}}; -use super::{thread::Thread, process::Process, synch::Semaphore}; +use super::{thread::Thread, process::Process}; pub const SIMULATORSTACKSIZE: usize = 32 * 1024; @@ -273,7 +273,7 @@ impl ThreadManager { mod test { use std::{rc::Rc, cell::RefCell}; - use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::Thread, process::Process, thread_manager::{ThreadManager, self}, synch::Semaphore}}; + use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::Thread, process::Process, thread_manager::ThreadManager, synch::Semaphore}}; #[test] fn test_thread_context() { @@ -334,7 +334,7 @@ mod test { // Init let mut tm = ThreadManager::new(); let mut machine = Machine::new(true); - let mut semaphore = Semaphore::new(2); + let semaphore = Semaphore::new(2); let sema_id = tm.get_obj_addrs().add_semaphore(semaphore); let thread1 = Rc::new(RefCell::new(Thread::new("test_semaphore_1"))); let thread2 = Rc::new(RefCell::new(Thread::new("test_semaphore_2"))); diff --git a/src/main.rs b/src/main.rs index c75f916..5de60b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ use clap::Parser; Burritos is an educational operating system written in Rust running on RISC-V emulator.", long_about = None)] +/// Launch argument parser struct Args { /// Enable debug mode #[arg(short, long)] diff --git a/src/utility/list.rs b/src/utility/list.rs index 772bad3..adc08fa 100644 --- a/src/utility/list.rs +++ b/src/utility/list.rs @@ -120,7 +120,7 @@ impl List { let mut current: *mut Node = self.head; let mut previous: *mut Node = ptr::null_mut(); while !current.is_null() { - if (&*current).elem == item { + if (*current).elem == item { if !previous.is_null() { (*previous).next = (*current).next; } else { diff --git a/src/utility/objaddr.rs b/src/utility/objaddr.rs index 4290df3..33f17dd 100644 --- a/src/utility/objaddr.rs +++ b/src/utility/objaddr.rs @@ -35,14 +35,14 @@ impl ObjAddr { /// Adds the **obj** Semaphore to self pub fn add_semaphore(&mut self, obj: Semaphore) -> i32 { - self.last_id = self.last_id + 1; + self.last_id += 1; self.semaphores.insert(self.last_id, obj); self.last_id } /// Adds the **obj** Lock to self pub fn add_lock(&mut self, obj: Lock) -> i32 { - self.last_id = self.last_id + 1; + self.last_id += 1; self.locks.insert(self.last_id, obj); self.last_id }