mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-27 03:13:23 +00:00
Reorganize the codebase
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
888853a6de
commit
271a16d492
32
services/libs/jinux-std/src/process/fifo_scheduler.rs
Normal file
32
services/libs/jinux-std/src/process/fifo_scheduler.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use crate::prelude::*;
|
||||
use jinux_frame::task::{set_scheduler, Scheduler, Task, TaskAdapter};
|
||||
|
||||
use intrusive_collections::LinkedList;
|
||||
|
||||
pub struct FifoScheduler {
|
||||
tasks: Mutex<LinkedList<TaskAdapter>>,
|
||||
}
|
||||
|
||||
impl FifoScheduler {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
tasks: Mutex::new(LinkedList::new(TaskAdapter::new())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Scheduler for FifoScheduler {
|
||||
fn enqueue(&self, task: Arc<Task>) {
|
||||
self.tasks.lock().push_back(task.clone());
|
||||
}
|
||||
|
||||
fn dequeue(&self) -> Option<Arc<Task>> {
|
||||
self.tasks.lock().pop_front()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
let fifo_scheduler = Box::new(FifoScheduler::new());
|
||||
let scheduler = Box::<FifoScheduler>::leak(fifo_scheduler);
|
||||
set_scheduler(scheduler);
|
||||
}
|
Reference in New Issue
Block a user