Add a task module with a Task struct

This commit is contained in:
Philipp Oppermann
2020-03-27 12:55:40 +01:00
parent 2cc188a403
commit dac7e67403
2 changed files with 23 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ pub mod gdt;
pub mod interrupts;
pub mod memory;
pub mod serial;
pub mod task;
pub mod vga_buffer;
pub fn init() {

22
src/task/mod.rs Normal file
View File

@@ -0,0 +1,22 @@
use alloc::boxed::Box;
use core::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
pub struct Task {
future: Pin<Box<dyn Future<Output = ()>>>,
}
impl Task {
pub fn new(future: impl Future<Output = ()> + 'static) -> Task {
Task {
future: Box::pin(future),
}
}
fn poll(&mut self, context: &mut Context) -> Poll<()> {
self.future.as_mut().poll(context)
}
}