Trait zerogc::GcContext [−][src]
pub unsafe trait GcContext: Sized { type System: GcSystem<Context = Self, Id = Self::Id>; type Id: CollectorId; unsafe fn basic_safepoint<T: Trace>(&mut self, value: &mut &mut T); unsafe fn freeze(&mut self); unsafe fn unfreeze(&mut self); unsafe fn recurse_context<T, F, R>(&self, value: &mut &mut T, func: F) -> R
where
T: Trace,
F: for<'gc> FnOnce(&'gc mut Self, &'gc mut T) -> R; }
The context of garbage collection, which can be frozen at a safepoint.
This is essentially used to maintain a shadow-stack to a set of roots, which are guarenteed not to be collected until a safepoint.
This context doesn’t necessarily support allocation (see GcSimpleAlloc for that).
Associated Types
type System: GcSystem<Context = Self, Id = Self::Id>
[src]
The system used with this context
type Id: CollectorId
[src]
The type of ids used in the system
Required methods
unsafe fn basic_safepoint<T: Trace>(&mut self, value: &mut &mut T)
[src]
Inform the garbage collection system we are at a safepoint and are ready for a potential garbage collection.
Safety
This method is unsafe and should never be invoked by user code.
See the safepoint! macro for a safe wrapper.
unsafe fn freeze(&mut self)
[src]
Inform the garbage collection system we are at a safepoint and are ready for a potential garbage collection.
Unlike a basic_safepoint
, the collector continues to
stay at the safepoint instead of returning immediately.
The context can’t be used for anything (including allocations),
until it is unfrozen.
This allows other threds to perform collections while this thread does other work (without using the GC).
The current contexts roots are considered invalid for the duration of the collection, since the collector could potentially relocate them.
Any parent contexts are fine and their roots will be preserved by collections.
Safety
Assumes this context is valid and not already frozen.
Don’t invoke this directly
unsafe fn unfreeze(&mut self)
[src]
Unfreeze this context, allowing it to be used again.
Safety
Must be a valid context! Must be currently frozen!
Don’t invoke this directly
unsafe fn recurse_context<T, F, R>(&self, value: &mut &mut T, func: F) -> R where
T: Trace,
F: for<'gc> FnOnce(&'gc mut Self, &'gc mut T) -> R,
[src]
T: Trace,
F: for<'gc> FnOnce(&'gc mut Self, &'gc mut T) -> R,
Invoke the closure with a temporary GcContext.
The specified value is guarenteed to live throughout the created context for the closure. However, because it could possibly be relocated by a collection, it’s bound to the lifetime of the sub-collector.
Safety
This macro doesn’t imply garbage collection, so it doesn’t mutate the collector directly. However the specified closure could trigger a collection in the sub-context. This would in undefined behavior if the collection invalidates a pointer tied to this context.
For this reason, this function should never be invoked by user code.
See the safepoint_recurse! macro for a safe wrapper
Implementors
impl GcContext for DummyContext
[src]
impl GcContext for DummyContext
[src]type System = DummySystem
type Id = DummyCollectorId
unsafe fn basic_safepoint<T: Trace>(&mut self, _value: &mut &mut T)
[src]
unsafe fn freeze(&mut self)
[src]
unsafe fn unfreeze(&mut self)
[src]
unsafe fn recurse_context<T, F, R>(&self, value: &mut &mut T, func: F) -> R where
T: Trace,
F: for<'gc> FnOnce(&'gc mut Self, &'gc mut T) -> R,
[src]
T: Trace,
F: for<'gc> FnOnce(&'gc mut Self, &'gc mut T) -> R,