pub struct FreezeState { /* private fields */ }Expand description
State for managing process freezing.
Uses an epoch counter to prevent race conditions where a freeze is scheduled but work arrives before it executes. The epoch is incremented on unfreeze, and freeze operations check the epoch matches before proceeding.
Supports freezing multiple PIDs (runtime + extensions) to accurately simulate
Lambda’s behaviour where the entire execution environment is frozen. PIDs can
be registered dynamically after creation using register_pid().
Implementations§
Source§impl FreezeState
impl FreezeState
Sourcepub fn new(mode: FreezeMode, pid: Option<u32>) -> Self
pub fn new(mode: FreezeMode, pid: Option<u32>) -> Self
Creates a new freeze state with a single PID (for backwards compatibility).
Sourcepub fn with_pids(mode: FreezeMode, pids: Vec<u32>) -> Self
pub fn with_pids(mode: FreezeMode, pids: Vec<u32>) -> Self
Creates a new freeze state with multiple PIDs.
Use this to freeze the runtime and all extension processes together, which accurately simulates Lambda’s freeze behaviour.
Sourcepub fn mode(&self) -> FreezeMode
pub fn mode(&self) -> FreezeMode
Returns the current freeze mode.
Sourcepub fn pid(&self) -> Option<i32>
pub fn pid(&self) -> Option<i32>
Returns the first configured PID, if any (for backwards compatibility).
Sourcepub fn register_pid(&self, pid: u32)
pub fn register_pid(&self, pid: u32)
Registers a PID to be frozen/unfrozen with the execution environment.
Call this after spawning runtime or extension processes to include them in freeze/thaw operations.
Sourcepub fn current_epoch(&self) -> u64
pub fn current_epoch(&self) -> u64
Returns the current freeze epoch.
Sourcepub async fn wait_for_state_change(&self)
pub async fn wait_for_state_change(&self)
Waits for the freeze state to change.
Sourcepub fn freeze_at_epoch(&self, epoch: u64) -> Result<bool, FreezeError>
pub fn freeze_at_epoch(&self, epoch: u64) -> Result<bool, FreezeError>
Attempts to freeze all configured processes at the given epoch.
The freeze will only proceed if the current epoch matches the provided epoch. This prevents race conditions where work arrives between scheduling and execution.
All configured PIDs (runtime and extensions) are frozen together to simulate Lambda’s behaviour where the entire execution environment is frozen.
Returns Ok(true) if frozen, Ok(false) if epoch mismatch (work arrived), Err on failure.
Sourcepub fn unfreeze(&self) -> Result<(), FreezeError>
pub fn unfreeze(&self) -> Result<(), FreezeError>
Unfreezes all configured processes and increments the epoch.
Incrementing the epoch cancels any pending freeze operations that were scheduled before this unfreeze.
Sourcepub fn force_unfreeze(&self)
pub fn force_unfreeze(&self)
Unconditionally unfreezes all configured processes without checking state.
Used during shutdown to ensure processes aren’t left frozen.