Added 2 tests to list.rs, improve semantic and using Default trait instant of function new

This commit is contained in:
Quentin Legot
2023-03-21 22:40:49 +01:00
parent d3b2d0bac6
commit b9c329219a
3 changed files with 54 additions and 20 deletions

View File

@ -26,7 +26,7 @@ impl Semaphore {
/// - *counter* initial value of counter
/// - *thread_manager* Thread manager which managing threads
pub fn new(counter: i32) -> Semaphore{
Semaphore { counter, waiting_queue: List::new()}
Semaphore { counter, waiting_queue: List::default() }
}
/// Decrement the value, and wait if it becomes < 0. Checking the
@ -98,7 +98,7 @@ impl Lock {
/// ### Parameters
/// - **thread_manager** Thread manager which managing threads
pub fn new() -> Lock {
Lock { owner: None, waiting_queue: List::new(), free: true }
Lock { owner: None, waiting_queue: List::default(), free: true }
}
/// Wait until the lock become free. Checking the
@ -196,7 +196,7 @@ impl Condition {
/// ### Parameters
/// - *thread_manager* Thread manager which managing threads
pub fn new() -> Condition {
Condition{ waiting_queue: List::new()}
Condition{ waiting_queue: List::default()}
}
/// Block the calling thread (put it in the wait queue).

View File

@ -28,8 +28,8 @@ impl ThreadManager {
Self {
g_current_thread: Option::None,
g_thread_to_be_destroyed: Option::None,
g_alive: List::new(),
ready_list: List::new(),
g_alive: List::default(),
ready_list: List::default(),
}
}