Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
		
							parent
							
								
									563d97f372
								
							
						
					
					
						commit
						49f1821f9c
					
				@ -1,8 +1,6 @@
 | 
			
		||||
mod fd;
 | 
			
		||||
pub mod iso9660;
 | 
			
		||||
 | 
			
		||||
use crate::serial_println;
 | 
			
		||||
 | 
			
		||||
use crate::drivers::atapi::read_block;
 | 
			
		||||
use crate::fd::FDt;
 | 
			
		||||
use crate::utils::unserialize;
 | 
			
		||||
 | 
			
		||||
@ -19,6 +19,8 @@ lazy_static! {
 | 
			
		||||
 | 
			
		||||
pub type Threadt = Arc<RefCell<Thread>>;
 | 
			
		||||
 | 
			
		||||
pub const K_THREAD_ID: ThreadId = ThreadId(0); // Kernel main thread identifier
 | 
			
		||||
 | 
			
		||||
struct ThreadStream {
 | 
			
		||||
    ids: ArrayQueue<ThreadId>,
 | 
			
		||||
    waker: AtomicWaker
 | 
			
		||||
@ -72,7 +74,7 @@ impl Scheduler {
 | 
			
		||||
            thread_queue: ThreadStream::new(),
 | 
			
		||||
        };
 | 
			
		||||
        let k_thread: Thread = Thread {
 | 
			
		||||
            id: ThreadId(0),
 | 
			
		||||
            id: K_THREAD_ID,
 | 
			
		||||
            entry_point: 0,
 | 
			
		||||
            started: true,
 | 
			
		||||
            rsp: 0,
 | 
			
		||||
@ -99,7 +101,7 @@ impl Scheduler {
 | 
			
		||||
        if self.threads.insert(thread_id, thread).is_some() {
 | 
			
		||||
            panic!("Duplicate thread ID")
 | 
			
		||||
        }
 | 
			
		||||
        if thread_id != ThreadId(0) {
 | 
			
		||||
        if thread_id != K_THREAD_ID {
 | 
			
		||||
            self.thread_queue.register(thread_id);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
use crate::println;
 | 
			
		||||
use crate::utils::mutex::AsyncMutex;
 | 
			
		||||
 | 
			
		||||
use super::scheduler::SCHEDULER;
 | 
			
		||||
use super::scheduler::{SCHEDULER, K_THREAD_ID};
 | 
			
		||||
 | 
			
		||||
use core::arch::asm;
 | 
			
		||||
use core::sync::atomic::{AtomicU64, Ordering};
 | 
			
		||||
@ -27,14 +27,22 @@ impl ThreadId {
 | 
			
		||||
 | 
			
		||||
pub fn exit() {
 | 
			
		||||
    println!("Exiting thread");
 | 
			
		||||
    {
 | 
			
		||||
        let mut scheduler = SCHEDULER.try_lock().unwrap();
 | 
			
		||||
        scheduler.exit(*RUNNING_THREAD.try_lock().unwrap());
 | 
			
		||||
    } // Drop scheduler mutex guard
 | 
			
		||||
 | 
			
		||||
    resume_k_thread();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub fn resume_k_thread() {
 | 
			
		||||
    let k_thread: *mut Thread;
 | 
			
		||||
    {
 | 
			
		||||
        let mut scheduler = SCHEDULER.try_lock().unwrap();
 | 
			
		||||
        k_thread = scheduler
 | 
			
		||||
            .get_thread(ThreadId(0))
 | 
			
		||||
            .get_thread(K_THREAD_ID)
 | 
			
		||||
            .unwrap()
 | 
			
		||||
            .as_ptr();
 | 
			
		||||
            scheduler.exit(*RUNNING_THREAD.try_lock().unwrap());
 | 
			
		||||
    } // Drop scheduler mutex guard
 | 
			
		||||
 | 
			
		||||
    unsafe {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user