@@ -11,10 +11,50 @@ use mmtk::Mutator;
11
11
use mmtk:: ObjectQueue ;
12
12
use mmtk:: Plan ;
13
13
14
- /// This is a hack to get the mutator iterator working.
15
- /// true -> task.mmutator
16
- /// false -> task.rts_mutator
17
- static mut ITERATOR : ( * const Task , bool ) = ( std:: ptr:: null ( ) , true ) ;
14
+ use core:: marker:: PhantomData ;
15
+
16
+ pub struct MutatorIterator < ' a > {
17
+ task : * const Task ,
18
+
19
+ /// true -> task.mmutator
20
+ /// false -> task.rts_mutator
21
+ which : bool ,
22
+ _marker : PhantomData < & ' a Task > ,
23
+ }
24
+
25
+ impl < ' a > MutatorIterator < ' a > {
26
+ pub unsafe fn new ( ) -> Self {
27
+ MutatorIterator {
28
+ task : all_tasks,
29
+ which : true ,
30
+ _marker : PhantomData ,
31
+ }
32
+ }
33
+ }
34
+
35
+ impl < ' a > Iterator for MutatorIterator < ' a > {
36
+ type Item = & ' a mut mmtk:: Mutator < GHCVM > ;
37
+
38
+ fn next ( & mut self ) -> Option < Self :: Item > {
39
+ unsafe {
40
+ if !self . task . is_null ( ) {
41
+ let result = match self . which {
42
+ true => ( * self . task ) . mmutator ,
43
+ false => ( * self . task ) . rts_mutator ,
44
+ } ;
45
+ if !self . which {
46
+ self . task = ( * self . task ) . all_next ;
47
+ self . which = true ;
48
+ } else {
49
+ self . which = false ;
50
+ }
51
+ Some ( std:: mem:: transmute ( result) )
52
+ } else {
53
+ None
54
+ }
55
+ }
56
+ }
57
+ }
18
58
19
59
pub struct VMActivePlan { }
20
60
@@ -37,32 +77,8 @@ impl ActivePlan<GHCVM> for VMActivePlan {
37
77
}
38
78
39
79
fn mutators < ' a > ( ) -> Box < dyn Iterator < Item = & ' a mut Mutator < GHCVM > > + ' a > {
40
- unimplemented ! ( )
41
- }
42
-
43
- fn reset_mutator_iterator ( ) {
44
- unsafe {
45
- ITERATOR = ( all_tasks, true ) ;
46
- }
47
- }
48
-
49
- fn get_next_mutator ( ) -> Option < & ' static mut Mutator < GHCVM > > {
50
80
unsafe {
51
- if !ITERATOR . 0 . is_null ( ) {
52
- let task = ITERATOR . 0 ;
53
- let result = match ITERATOR . 1 {
54
- true => ( * task) . mmutator ,
55
- false => ( * task) . rts_mutator ,
56
- } ;
57
- if !ITERATOR . 1 {
58
- ITERATOR = ( ( * task) . all_next , true ) ;
59
- } else {
60
- ITERATOR = ( ITERATOR . 0 , false ) ;
61
- }
62
- Some ( std:: mem:: transmute ( result) )
63
- } else {
64
- None
65
- }
81
+ Box :: new ( MutatorIterator :: new ( ) )
66
82
}
67
83
}
68
84
0 commit comments