mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Use SimpleExecutor in kernel_main to run example_task
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use alloc::{boxed::Box, rc::Rc, vec, vec::Vec};
|
|
||||||
use blog_os::println;
|
use blog_os::println;
|
||||||
|
use blog_os::task::{simple_executor::SimpleExecutor, Task};
|
||||||
use bootloader::{entry_point, BootInfo};
|
use bootloader::{entry_point, BootInfo};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
@@ -27,29 +27,9 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|||||||
|
|
||||||
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
||||||
|
|
||||||
// allocate a number on the heap
|
let mut executor = SimpleExecutor::new();
|
||||||
let heap_value = Box::new(41);
|
executor.spawn(Task::new(example_task()));
|
||||||
println!("heap_value at {:p}", heap_value);
|
executor.run();
|
||||||
|
|
||||||
// create a dynamically sized vector
|
|
||||||
let mut vec = Vec::new();
|
|
||||||
for i in 0..500 {
|
|
||||||
vec.push(i);
|
|
||||||
}
|
|
||||||
println!("vec at {:p}", vec.as_slice());
|
|
||||||
|
|
||||||
// create a reference counted vector -> will be freed when count reaches 0
|
|
||||||
let reference_counted = Rc::new(vec![1, 2, 3]);
|
|
||||||
let cloned_reference = reference_counted.clone();
|
|
||||||
println!(
|
|
||||||
"current reference count is {}",
|
|
||||||
Rc::strong_count(&cloned_reference)
|
|
||||||
);
|
|
||||||
core::mem::drop(reference_counted);
|
|
||||||
println!(
|
|
||||||
"reference count is {} now",
|
|
||||||
Rc::strong_count(&cloned_reference)
|
|
||||||
);
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|||||||
Reference in New Issue
Block a user