MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / new_stack

Method new_stack

crates/core/src/host/wasmtime/pooling_stack_creator.rs:61–77  ·  view source on GitHub ↗
(&self, size: usize, zeroed: bool)

Source from the content-addressed store, hash-verified

59// and are not modified elsewhere.
60unsafe impl StackCreator for PoolingStackCreator {
61 fn new_stack(&self, size: usize, zeroed: bool) -> anyhow::Result<Box<dyn wasmtime::StackMemory>, anyhow::Error> {
62 assert_eq!(size, ASYNC_STACK_SIZE);
63
64 // SAFETY: `self.weak` is fully initialized whenever `new_stack` is called.
65 let weak = self.weak.clone();
66
67 // Either take the stack from the pool
68 // or fall back to creating a new one.
69 let stack = weak
70 .upgrade()
71 .and_then(|pool| pool.pool.pop().map(Ok))
72 .unwrap_or_else(|| FiberStack::new(ASYNC_STACK_SIZE, zeroed))?;
73
74 // Ship it.
75 let stack = ManuallyDrop::new(stack);
76 Ok(Box::new(PooledFiberStack { stack, weak }))
77 }
78}
79
80impl PoolingStackCreator {

Callers

nothing calls this directly

Calls 5

newFunction · 0.50
OkFunction · 0.50
cloneMethod · 0.45
upgradeMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected