Kernel documentation. Still need to do thread.rs
This commit is contained in:
parent
2f38edee70
commit
e430a62c35
@ -1,3 +1,8 @@
|
|||||||
|
//! # Exceprions
|
||||||
|
//!
|
||||||
|
//! This module Enum the constant values of the exceptions.
|
||||||
|
//! They are used to stop the system to execute some opperation
|
||||||
|
|
||||||
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}}};
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
//! # Error Code
|
||||||
|
//!
|
||||||
|
//! This module enumerate the possibles error code who could get in a function
|
||||||
|
//!
|
||||||
|
//! **Basic Usage:*
|
||||||
|
//!
|
||||||
|
//! Result<YourSuccessStruct, **ErrorCode**
|
||||||
|
|
||||||
#![allow(unused, clippy::missing_docs_in_private_items)]
|
#![allow(unused, clippy::missing_docs_in_private_items)]
|
||||||
/// Error enum, use it with Result<YourSucessStruct, **ErrorCode**>
|
/// Error enum, use it with Result<YourSucessStruct, **ErrorCode**>
|
||||||
pub enum ErrorCode {
|
pub enum ErrorCode {
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
//! # Kernel
|
||||||
|
//!
|
||||||
|
//! This module contains all the tool required for the kernel to work.
|
||||||
|
//!
|
||||||
|
//! Currently it contains the scheduling and synchroisation tools, but it will contains the tools
|
||||||
|
//! required Memory gestion, Files gestion and peripheral pilots.
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub mod thread;
|
pub mod thread;
|
||||||
pub mod mgerror;
|
pub mod mgerror;
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
//! # Synchronisation
|
||||||
|
//!
|
||||||
|
//! This module contains some scheduling and synchronisation utilities:
|
||||||
|
//! - **Semaphore**
|
||||||
|
//! - **Lock**
|
||||||
|
//!
|
||||||
|
//! Conditions aren't implemented currently
|
||||||
|
|
||||||
use crate::utility::list::List;
|
use crate::utility::list::List;
|
||||||
use crate::kernel::thread::Thread;
|
use crate::kernel::thread::Thread;
|
||||||
use crate::simulator::interrupt::InterruptStatus::InterruptOff;
|
use crate::simulator::interrupt::InterruptStatus::InterruptOff;
|
||||||
@ -6,13 +14,14 @@ use std::cell::RefCell;
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use super::thread_manager::ThreadManager;
|
use super::thread_manager::ThreadManager;
|
||||||
|
|
||||||
/// Structure of a Semaphore used for synchronisation
|
/// Structure of a Semaphore used for synchronisation.
|
||||||
|
/// It use a counter to determine the number of thread that can be executed simultaneously.
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub struct Semaphore {
|
pub struct Semaphore {
|
||||||
|
|
||||||
/// Counter of simultanous Semaphore
|
/// Counter of simultaneous Semaphore
|
||||||
pub counter:i32,
|
pub counter:i32,
|
||||||
/// QUeue of Semaphore waiting to be exucated
|
/// QUeue of Semaphore waiting to be executed
|
||||||
pub waiting_queue:List<Rc<RefCell<Thread>>>,
|
pub waiting_queue:List<Rc<RefCell<Thread>>>,
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -49,7 +58,7 @@ pub struct Lock {
|
|||||||
impl Lock {
|
impl Lock {
|
||||||
|
|
||||||
/// Initialize a Lock, so that it can be used for synchronization.
|
/// Initialize a Lock, so that it can be used for synchronization.
|
||||||
/// The lock is initialy free
|
/// The lock is initially free
|
||||||
///
|
///
|
||||||
/// ### Parameters
|
/// ### Parameters
|
||||||
/// - **thread_manager** Thread manager which managing threads
|
/// - **thread_manager** Thread manager which managing threads
|
||||||
@ -72,7 +81,7 @@ impl Lock {
|
|||||||
let old_status = machine.interrupt.set_status(InterruptOff);
|
let old_status = machine.interrupt.set_status(InterruptOff);
|
||||||
if self.free {
|
if self.free {
|
||||||
self.free = false;
|
self.free = false;
|
||||||
self.owner = Option::Some(match thread_manager.get_g_current_thread() {
|
self.owner = Some(match thread_manager.get_g_current_thread() {
|
||||||
Some(th) => {
|
Some(th) => {
|
||||||
Rc::clone(&th)
|
Rc::clone(&th)
|
||||||
},
|
},
|
||||||
@ -128,8 +137,14 @@ impl Lock {
|
|||||||
machine.interrupt.set_status(old_status);
|
machine.interrupt.set_status(old_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if the current thread holds this lock.
|
/// Say if the lock is held by the current thread
|
||||||
/// Useful for checking in Release, and in Condition operations below.
|
/// Useful for checking in Release, and in Condition operations below.
|
||||||
|
/// ### Parameters
|
||||||
|
/// - **self** The current lock
|
||||||
|
/// - **thread-manager** The thread manager present in the system
|
||||||
|
/// ### Return
|
||||||
|
/// True if the current thread holds this lock.
|
||||||
|
|
||||||
pub fn held_by_current_thread(&mut self, thread_manager: &mut ThreadManager) -> bool {
|
pub fn held_by_current_thread(&mut self, thread_manager: &mut ThreadManager) -> bool {
|
||||||
match &self.owner {
|
match &self.owner {
|
||||||
Some(x) =>
|
Some(x) =>
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//! # Thread
|
||||||
|
//!
|
||||||
|
//!
|
||||||
use std::{rc::Rc, cell::RefCell};
|
use std::{rc::Rc, cell::RefCell};
|
||||||
|
|
||||||
use super::{process::Process, thread_manager::ThreadRef};
|
use super::{process::Process, thread_manager::ThreadRef};
|
||||||
|
Loading…
Reference in New Issue
Block a user