Macro axtask::def_task_ext

source ·
macro_rules! def_task_ext {
    ($task_ext_struct:ty) => { ... };
}
Expand description

Define the task extended data.

It automatically implements TaskExtRef and TaskExtMut for TaskInner.

§Example

use axtask::{def_task_ext, TaskExtRef, TaskInner};

pub struct TaskExtImpl {
   proc_id: usize,
}

def_task_ext!(TaskExtImpl);

axtask::init_scheduler();

let mut inner = TaskInner::new(|| {},  "".into(), 0x1000);
assert!(inner.init_task_ext(TaskExtImpl { proc_id: 233 }).is_some());
// cannot initialize twice
assert!(inner.init_task_ext(TaskExtImpl { proc_id: 0xdead }).is_none());

let task = axtask::spawn_task(inner);
assert_eq!(task.task_ext().proc_id, 233);