@@ -4,30 +4,34 @@ use crate::custom_event::RuffleEvent;
4
4
use crate :: task:: Task ;
5
5
use crate :: EventSender ;
6
6
use async_channel:: { unbounded, Receiver , Sender } ;
7
- use generational_arena:: { Arena , Index } ;
8
7
use ruffle_core:: backend:: navigator:: OwnedFuture ;
9
8
use ruffle_core:: loader:: Error ;
9
+ use slotmap:: { new_key_type, SlotMap } ;
10
10
use std:: sync:: { Arc , Mutex , Weak } ;
11
11
use std:: task:: { Context , Poll , RawWaker , RawWakerVTable , Waker } ;
12
12
13
+ new_key_type ! {
14
+ struct TaskKey ;
15
+ }
16
+
13
17
/// Exeuctor context passed to event sources.
14
18
///
15
19
/// All task handles are identical and interchangeable. Cloning a `TaskHandle`
16
20
/// does not clone the underlying task.
17
21
#[ derive( Clone ) ]
18
22
struct TaskHandle {
19
- /// The arena handle for a given task.
20
- handle : Index ,
23
+ /// The slotmap key for a given task.
24
+ key : TaskKey ,
21
25
22
26
/// The executor the task belongs to.
23
27
executor : Arc < Mutex < NativeAsyncExecutor > > ,
24
28
}
25
29
26
30
impl TaskHandle {
27
31
/// Construct a handle to a given task.
28
- fn for_task ( task : Index , executor : Arc < Mutex < NativeAsyncExecutor > > ) -> Self {
32
+ fn for_task ( task : TaskKey , executor : Arc < Mutex < NativeAsyncExecutor > > ) -> Self {
29
33
Self {
30
- handle : task,
34
+ key : task,
31
35
executor,
32
36
}
33
37
}
@@ -50,7 +54,7 @@ impl TaskHandle {
50
54
self . executor
51
55
. lock ( )
52
56
. expect ( "able to lock executor" )
53
- . wake ( self . handle ) ;
57
+ . wake ( self . key ) ;
54
58
}
55
59
56
60
/// Convert a voidptr into an `TaskHandle` reference, if non-null.
@@ -123,7 +127,7 @@ impl TaskHandle {
123
127
124
128
pub struct NativeAsyncExecutor {
125
129
/// List of all spawned tasks.
126
- task_queue : Arena < Task > ,
130
+ task_queue : SlotMap < TaskKey , Task > ,
127
131
128
132
/// Source of tasks sent to us by the `NavigatorBackend`.
129
133
channel : Receiver < OwnedFuture < ( ) , Error > > ,
@@ -147,7 +151,7 @@ impl NativeAsyncExecutor {
147
151
let ( send, recv) = unbounded ( ) ;
148
152
let new_self = Arc :: new_cyclic ( |self_ref| {
149
153
Mutex :: new ( Self {
150
- task_queue : Arena :: new ( ) ,
154
+ task_queue : SlotMap :: with_key ( ) ,
151
155
channel : recv,
152
156
self_ref : self_ref. clone ( ) ,
153
157
event_sender,
@@ -193,7 +197,7 @@ impl NativeAsyncExecutor {
193
197
}
194
198
195
199
/// Mark a task as ready to proceed.
196
- fn wake ( & mut self , task : Index ) {
200
+ fn wake ( & mut self , task : TaskKey ) {
197
201
if let Some ( task) = self . task_queue . get_mut ( task) {
198
202
if !task. is_completed ( ) {
199
203
task. set_ready ( ) ;
0 commit comments