Skip to content

Commit adf9282

Browse files
committed
Replace GC tracking HashSet with intrusive linked list
Replace per-generation HashSet<GcObjectPtr> with intrusive doubly-linked lists for GC object tracking. Each PyInner now carries gc_pointers (prev/next) and gc_generation fields, enabling O(1) track/untrack without hashing. - Add gc_pointers (Pointers<PyObject>) and gc_generation (u8) to PyInner - Implement GcLink trait for intrusive list integration - Replace generation_objects/permanent_objects/tracked_objects/finalized_objects HashSets with generation_lists/permanent_list LinkedLists - Use GcBits::FINALIZED flag instead of finalized_objects HashSet - Change default_dealloc to untrack directly before memory free - Hold both src/dst list locks in promote_survivors to prevent race conditions with concurrent untrack_object calls - Add pop_front to LinkedList for freeze/unfreeze operations
1 parent 3cbd08f commit adf9282

File tree

4 files changed

+263
-262
lines changed

4 files changed

+263
-262
lines changed

crates/common/src/linked_list.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,20 @@ impl<L: Link> LinkedList<L, L::Target> {
192192
// }
193193
// }
194194

195+
/// Removes the first element from the list and returns it, or None if empty.
196+
pub fn pop_front(&mut self) -> Option<L::Handle> {
197+
let head = self.head?;
198+
unsafe {
199+
self.head = L::pointers(head).as_ref().get_next();
200+
if let Some(new_head) = self.head {
201+
L::pointers(new_head).as_mut().set_prev(None);
202+
}
203+
L::pointers(head).as_mut().set_next(None);
204+
L::pointers(head).as_mut().set_prev(None);
205+
Some(L::from_raw(head))
206+
}
207+
}
208+
195209
/// Returns whether the linked list does not contain any node
196210
pub const fn is_empty(&self) -> bool {
197211
self.head.is_none()

0 commit comments

Comments
 (0)