Skip to content

Commit c886157

Browse files
bgamariJunmingZhao42
authored andcommitted
Rework MutatorIterator interface
To reflect upstream changes made in mmtk/mmtk-core#817.
1 parent 6899453 commit c886157

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

rts/mmtk/mmtk/src/active_plan.rs

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,50 @@ use mmtk::Mutator;
1111
use mmtk::ObjectQueue;
1212
use mmtk::Plan;
1313

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+
}
1858

1959
pub struct VMActivePlan {}
2060

@@ -37,32 +77,8 @@ impl ActivePlan<GHCVM> for VMActivePlan {
3777
}
3878

3979
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>> {
5080
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())
6682
}
6783
}
6884

0 commit comments

Comments
 (0)