mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 06:17:49 +00:00
Fix wrong calculation of task ID
Pin implements Deref too, so by dereferencing only once we get a `&Box` reference. Since Box also implements Future, the type of `future_ref` was still correct. To avoid this error in the future, we added an assertion to catch duplicate task IDson `pending_tasks.insert()`.
This commit is contained in:
@@ -58,7 +58,9 @@ impl Executor {
|
||||
Poll::Pending => {
|
||||
// add task to pending_tasks list and wait for wakeup
|
||||
let task_id = Self::task_id(&task);
|
||||
self.pending_tasks.insert(task_id, task);
|
||||
if self.pending_tasks.insert(task_id, task).is_some() {
|
||||
panic!("Task with same ID already in pending_tasks queue");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +77,7 @@ impl Executor {
|
||||
}
|
||||
|
||||
fn task_id(task: &Task) -> TaskId {
|
||||
let future_ref: &dyn Future<Output = ()> = &*task;
|
||||
let future_ref: &dyn Future<Output = ()> = &**task;
|
||||
future_ref as *const _ as *const () as usize
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user