Skip to content

Commit b55479f

Browse files
committed
Use weak task references in runtime ready queue
Seems logical that the only strong references are needed in the activity itself. Just realised this while trying to explain in a devlog :^)
1 parent a5538b4 commit b55479f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

game/simulation/src/runtime/runtime.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use crate::event::EntityEvent;
1919
use crate::runtime::futures::ParkUntilWakeupFuture;
2020

2121
struct RuntimeInner {
22-
ready: Vec<TaskRef>,
22+
ready: Vec<WeakTaskRef>,
2323
/// Swapped out with `ready` during tick
24-
ready_double_buf: Vec<TaskRef>,
24+
ready_double_buf: Vec<WeakTaskRef>,
2525

2626
next_task: TaskHandle,
2727

@@ -96,7 +96,7 @@ impl Runtime {
9696
let _ = gimme_task_ref.send(task.clone());
9797

9898
// task is ready immediately
99-
runtime.ready.push(task.clone());
99+
runtime.ready.push(task.weak());
100100
task.0.ready.store(true, Ordering::Relaxed);
101101
task
102102
}
@@ -119,7 +119,7 @@ impl Runtime {
119119
};
120120

121121
drop(runtime);
122-
for task in ready_tasks.drain(..) {
122+
for task in ready_tasks.drain(..).filter_map(|t| t.upgrade()) {
123123
let was_ready = task.0.ready.swap(false, Ordering::Relaxed);
124124
debug_assert!(was_ready, "task should've been ready but wasn't");
125125

@@ -147,7 +147,7 @@ impl Runtime {
147147
!self.is_ready(task.handle()),
148148
"task handle ready flag is wrong, should be not ready"
149149
);
150-
self.0.borrow_mut().ready.push(task.clone());
150+
self.0.borrow_mut().ready.push(task.weak());
151151
} else {
152152
debug_assert!(
153153
self.is_ready(task.handle()),
@@ -165,6 +165,7 @@ impl Runtime {
165165
.borrow()
166166
.ready
167167
.iter()
168+
.filter_map(|t| t.upgrade())
168169
.position(|t| t.handle() == task)
169170
}
170171
}

0 commit comments

Comments
 (0)