Skip to main content

validate_write

Function validate_write 

Source
pub fn validate_write(token: u64, current_token: u64) -> bool
Expand description

Validate that a write carrying token is still allowed against a resource whose last-seen fencing token is current_token.

This is the canonical guard external systems should place in front of any side-effecting write protected by an ash-lock lock. A write is only safe if its token is at least the highest token the resource has observed; any smaller token belongs to a lease that has since been superseded (e.g. a paused process whose lock expired and was re-acquired elsewhere).

use ash_lock::validate_write;
assert!(validate_write(7, 7));   // current holder
assert!(validate_write(8, 7));   // newer holder writing first
assert!(!validate_write(6, 7));  // stale holder — reject!