pub struct ShmWriter { /* private fields */ }Expand description
Writer to the ClockBound shared memory segment.
This writer is expected to be used by a single process writing to a given path. The file written to is memory mapped by the writer and many (read-only) readers. Updates to the memory segment are applied in a lock-free manner, using a rolling generation number to protect the update section.
Implementations§
Source§impl ShmWriter
impl ShmWriter
Sourcepub fn new(
path: &Path,
minimum_version: ClockErrorBoundLayoutVersion,
current_version: ClockErrorBoundLayoutVersion,
) -> Result<ShmWriter>
pub fn new( path: &Path, minimum_version: ClockErrorBoundLayoutVersion, current_version: ClockErrorBoundLayoutVersion, ) -> Result<ShmWriter>
Create a new ShmWriter referencing the memory segment to write ClockErrorBound data to.
There are several cases to consider:
- The file backing the memory segment does not exist, or the content is corrupted/wrong. This is a cold start-like scenario, creating a fresh memory mapped file.
- The file backing the memory segment already exist and is valid. This may be that the process using this writer has restarted, but clients may still be using the existing values. Here, we want to load the existing memory segment, and continue as if nothing happened. That’s a warm reboot-like scenario.
- A variation of 2., but where the layout is being changed (a version bump). This is analog to a cold boot.
Trait Implementations§
Source§impl Drop for ShmWriter
impl Drop for ShmWriter
Source§impl ShmWrite for ShmWriter
impl ShmWrite for ShmWriter
Source§fn write(&mut self, ceb: &ClockErrorBound)
fn write(&mut self, ceb: &ClockErrorBound)
Update the clock error bound data in the memory segment.
This function implements the lock-free mechanism that lets the writer update the memory segment shared with many readers. The generation number is set to an odd number before the update and an even number when successfully completed.
Note that the generation number rolls over, but is never set back to 0, as it would otherwise signal the readers that the segment is not initialized.