pub struct GcScope<'s> { /* private fields */ }Implementations§
Source§impl<'s> GcScope<'s>
impl<'s> GcScope<'s>
Sourcepub fn new(heap: &'s mut GcHeap, partition_id: GcPartitionId) -> Self
pub fn new(heap: &'s mut GcHeap, partition_id: GcPartitionId) -> Self
Examples found in repository?
29fn alloc_static(
30 heap: &mut GcHeap,
31 scope: GcPartitionId,
32 value: i32,
33) -> GcResult<GcRef<StaticNode>> {
34 let ctx = GcScope::new(heap, scope);
35 let r = ctx
36 .alloc_local(StaticNode { _value: value })
37 .map_err(|(err, _)| err)?;
38 ctx.flush();
39 Ok(r)
40}
41
42fn alloc_other(heap: &mut GcHeap, scope: GcPartitionId, value: i32) -> GcResult<GcRef<OtherNode>> {
43 let ctx = GcScope::new(heap, scope);
44 let r = ctx
45 .alloc_local(OtherNode { _value: value })
46 .map_err(|(err, _)| err)?;
47 ctx.flush();
48 Ok(r)
49}pub fn new_scope<'child>(&'child mut self) -> GcScope<'child>where
's: 'child,
pub fn with_new_scope<R>(&self, f: impl FnOnce(GcScope<'_>) -> R) -> R
Methods from Deref<Target = GcScopeState<'s>>§
pub fn partition_id(&self) -> GcPartitionId
pub fn heap(&self) -> &GcHeap
pub fn heap_mut(&mut self) -> &mut GcHeap
pub fn depth(&self) -> u8
pub fn count(&self) -> usize
Sourcepub fn parent(&self) -> Option<(&GcScopeState<'_>, u8)>
pub fn parent(&self) -> Option<(&GcScopeState<'_>, u8)>
get parent scope, and its level.
pub fn alloc_root<T: GcNode>( &self, payload: T, ) -> Result<GcRef<T>, (GcError, T)>
Sourcepub fn alloc_local<T: GcNode>(
&self,
payload: T,
) -> Result<GcRef<T>, (GcError, T)>
pub fn alloc_local<T: GcNode>( &self, payload: T, ) -> Result<GcRef<T>, (GcError, T)>
alloc a local node in scope.
Examples found in repository?
29fn alloc_static(
30 heap: &mut GcHeap,
31 scope: GcPartitionId,
32 value: i32,
33) -> GcResult<GcRef<StaticNode>> {
34 let ctx = GcScope::new(heap, scope);
35 let r = ctx
36 .alloc_local(StaticNode { _value: value })
37 .map_err(|(err, _)| err)?;
38 ctx.flush();
39 Ok(r)
40}
41
42fn alloc_other(heap: &mut GcHeap, scope: GcPartitionId, value: i32) -> GcResult<GcRef<OtherNode>> {
43 let ctx = GcScope::new(heap, scope);
44 let r = ctx
45 .alloc_local(OtherNode { _value: value })
46 .map_err(|(err, _)| err)?;
47 ctx.flush();
48 Ok(r)
49}pub fn add_non_local(&self, node: NonNull<GcHead>) -> bool
Sourcepub fn remove_node(&self, node: NonNull<GcHead>) -> bool
pub fn remove_node(&self, node: NonNull<GcHead>) -> bool
Remove a LOCAL node from this scope’s cache and clear its LOCAL flag.
This is the inverse of add_node: it undoes the LOCAL protection
that was granted when the node was allocated in this scope.
After this call, the node is no longer protected by this scope
and will be traced by GC solely through other GC references.
Returns true if the node was found and removed from this scope’s cache.
Returns false if the node was not in this scope’s cache (e.g., it was
already promoted, or belongs to a different scope).
§Safety
The caller must ensure the node is still alive and valid.
This method does NOT check whether the node is the current promote node;
the caller (e.g., ScopedContext::throw) is responsible for ensuring
the node is not the promote target.
pub fn get_promote(&self) -> Option<NonNull<GcHead>>
Sourcepub fn set_promote(&self, node: Option<NonNull<GcHead>>)
pub fn set_promote(&self, node: Option<NonNull<GcHead>>)
Set a node to be promoted.
Promote means when the scope is dropped, the node will be added to upper scope.
Sourcepub fn flush(&self)
pub fn flush(&self)
clear and unprotect locals nodes in this scope; promote the result node to upper scope.
Examples found in repository?
29fn alloc_static(
30 heap: &mut GcHeap,
31 scope: GcPartitionId,
32 value: i32,
33) -> GcResult<GcRef<StaticNode>> {
34 let ctx = GcScope::new(heap, scope);
35 let r = ctx
36 .alloc_local(StaticNode { _value: value })
37 .map_err(|(err, _)| err)?;
38 ctx.flush();
39 Ok(r)
40}
41
42fn alloc_other(heap: &mut GcHeap, scope: GcPartitionId, value: i32) -> GcResult<GcRef<OtherNode>> {
43 let ctx = GcScope::new(heap, scope);
44 let r = ctx
45 .alloc_local(OtherNode { _value: value })
46 .map_err(|(err, _)| err)?;
47 ctx.flush();
48 Ok(r)
49}