Skip to content

Commit 98eef79

Browse files
committed
background_callback_gc_collect: We must traverse the whole list
1 parent 6912d31 commit 98eef79

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

supervisor/shared/background_callback.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ void background_callback_reset() {
108108
}
109109

110110
void background_callback_gc_collect(void) {
111+
// We don't enter the callback critical section here. We rely on
112+
// gc_collect_ptr _NOT_ entering background callbacks, so it is not
113+
// possible for the list to be cleared.
114+
//
115+
// However, it is possible for the list to be extended. We make the
116+
// minor assumption that no newly added callback is for a
117+
// collectable object. That is, we only plug the hole where an
118+
// object becomes collectable AFTER it is added but before the
119+
// callback is run, not the hole where an object was ALREADY
120+
// collectable but adds a background task for itself.
121+
//
122+
// It's necessary to traverse the whole list here, as the callbacks
123+
// themselves can be in non-gc memory, and some of the cb->data
124+
// objects themselves might be in non-gc memory.
111125
background_callback_t *cb = (background_callback_t*)callback_head;
112-
gc_collect_ptr(cb);
126+
while(cb) {
127+
gc_collect_ptr(cb->data);
128+
cb = cb->next;
129+
}
113130
}

0 commit comments

Comments
 (0)