mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-27 14:40:44 +00:00
wip: add tracking for tasks
This commit is contained in:
parent
6f10af0cc5
commit
ce17574aa0
1 changed files with 7 additions and 5 deletions
|
@ -7,7 +7,7 @@ use std::{
|
||||||
any::{Any, TypeId},
|
any::{Any, TypeId},
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
cell::{Cell, RefCell},
|
cell::{Cell, RefCell},
|
||||||
collections::HashMap,
|
collections::{HashMap, HashSet},
|
||||||
future::Future,
|
future::Future,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
|
@ -179,6 +179,9 @@ impl ScopeArena {
|
||||||
log::trace!("removing scope {:?}", id);
|
log::trace!("removing scope {:?}", id);
|
||||||
self.ensure_drop_safety(id);
|
self.ensure_drop_safety(id);
|
||||||
|
|
||||||
|
//
|
||||||
|
let tasks = self.tasks.tasks.borrow_mut();
|
||||||
|
|
||||||
// Safety:
|
// Safety:
|
||||||
// - ensure_drop_safety ensures that no references to this scope are in use
|
// - ensure_drop_safety ensures that no references to this scope are in use
|
||||||
// - this raw pointer is removed from the map
|
// - this raw pointer is removed from the map
|
||||||
|
@ -933,14 +936,17 @@ impl BumpFrame {
|
||||||
|
|
||||||
pub(crate) struct TaskQueue {
|
pub(crate) struct TaskQueue {
|
||||||
pub(crate) tasks: RefCell<FxHashMap<TaskId, InnerTask>>,
|
pub(crate) tasks: RefCell<FxHashMap<TaskId, InnerTask>>,
|
||||||
|
pub(crate) task_map: RefCell<FxHashMap<ScopeId, HashSet<TaskId>>>,
|
||||||
gen: Cell<usize>,
|
gen: Cell<usize>,
|
||||||
sender: UnboundedSender<SchedulerMsg>,
|
sender: UnboundedSender<SchedulerMsg>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type InnerTask = Pin<Box<dyn Future<Output = ()>>>;
|
pub(crate) type InnerTask = Pin<Box<dyn Future<Output = ()>>>;
|
||||||
impl TaskQueue {
|
impl TaskQueue {
|
||||||
fn new(sender: UnboundedSender<SchedulerMsg>) -> Rc<Self> {
|
fn new(sender: UnboundedSender<SchedulerMsg>) -> Rc<Self> {
|
||||||
Rc::new(Self {
|
Rc::new(Self {
|
||||||
tasks: RefCell::new(FxHashMap::default()),
|
tasks: RefCell::new(FxHashMap::default()),
|
||||||
|
task_map: RefCell::new(FxHashMap::default()),
|
||||||
gen: Cell::new(0),
|
gen: Cell::new(0),
|
||||||
sender,
|
sender,
|
||||||
})
|
})
|
||||||
|
@ -957,10 +963,6 @@ impl TaskQueue {
|
||||||
fn remove_fut(&self, id: TaskId) {
|
fn remove_fut(&self, id: TaskId) {
|
||||||
if let Ok(mut tasks) = self.tasks.try_borrow_mut() {
|
if let Ok(mut tasks) = self.tasks.try_borrow_mut() {
|
||||||
let _ = tasks.remove(&id);
|
let _ = tasks.remove(&id);
|
||||||
} else {
|
|
||||||
// todo: it should be okay to remote a fut while the queue is being polled
|
|
||||||
// However, it's not currently possible to do that.
|
|
||||||
log::trace!("Unable to remove task from task queue. This is probably a bug.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub(crate) fn has_tasks(&self) -> bool {
|
pub(crate) fn has_tasks(&self) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue