pub struct MappedClock<Reference: Timeline, Output: Timeline> { /* private fields */ }Expand description
A clock backed by memory mapped into this process’ virtual address space.
A memory mapped clock can be read more efficiently than a regular kernel clock object in contexts where making syscalls are undesirable, for example for efficiency reasons.
A memory mapped clock will clean up after itself when going out of scope.
To create one, you will need a zx::Clock, a zx::Vmar and a call to MappedClock::try_new.
Implementations§
Source§impl<Reference: Timeline, Output: Timeline> MappedClock<Reference, Output>
impl<Reference: Timeline, Output: Timeline> MappedClock<Reference, Output>
Sourcepub fn try_new(
clock: Clock<Reference, Output>,
parent_vmar: &Vmar,
vmar_flags: VmarFlags,
) -> Result<MappedClock<Reference, Output>, Status>
pub fn try_new( clock: Clock<Reference, Output>, parent_vmar: &Vmar, vmar_flags: VmarFlags, ) -> Result<MappedClock<Reference, Output>, Status>
Tries to convert the supplied regular clock into a memory mapped clock.
A memory mapped clock can be read more efficiently than a regular kernel clock object in contexts where calling into the kernel is undesirable. At the same time, updates to the memory mapped clock can be observed consistently with any other observers of the same underlying clock, a property guaranteed by Zircon.
As a tradeoff, a memory mapped clock may offer a restricted set of methods, and has more complex construction and lifecycle as compared to zx::Clock.
To ensure that there is no confusion as to how the clock is accessed, this
conversion consumes zx::Clock, and is not reversible. If you need
to use Self both as a regular and mapped clock, it is probably a good idea
to call duplicate_handle() on zx::Clock before calling this method.
§Args
clock: the clock to convert to a mapped clock.parent_vmar: a handle to the virtual memory address range to map the clock into. The clock will be unmapped when Self goes out of scope. Must be cloneable.vmar_flags: flags to apply when mapping the clock. Usually this needs to be at leastzx::VmarFlags::PERM_READ.
§Errors
The conversion may fail if clock was not created as a mappable clock using
[ClockOpts::MAPPABLE] at its creation time.
Sourcepub fn try_new_with_offset(
clock: Clock<Reference, Output>,
parent_vmar: &Vmar,
vmar_flags: VmarFlags,
offset: u64,
) -> Result<MappedClock<Reference, Output>, Status>
pub fn try_new_with_offset( clock: Clock<Reference, Output>, parent_vmar: &Vmar, vmar_flags: VmarFlags, offset: u64, ) -> Result<MappedClock<Reference, Output>, Status>
Same as [try_new], but allows mapping with a specified offset.
§Args
Same as [try_new], except:
vmar_flags: must includeSPECIFICifoffsetis not zero.
Sourcepub fn try_new_without_unmap(
clock: &Clock<Reference, Output>,
parent_vmar: &Vmar,
vmar_flags: VmarFlags,
offset: u64,
) -> Result<MappedClock<Reference, Output>, Status>
pub fn try_new_without_unmap( clock: &Clock<Reference, Output>, parent_vmar: &Vmar, vmar_flags: VmarFlags, offset: u64, ) -> Result<MappedClock<Reference, Output>, Status>
Same as try_new, but does not unmap the clock at end of this struct’s lifetime.
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
The size of the memory region occupied by this memory mapped clock.
Sourcepub fn read(&self) -> Result<Instant<Output>, Status>
pub fn read(&self) -> Result<Instant<Output>, Status>
Read the clock indication.
This is the same method as on [Clock].
Sourcepub fn get_details(&self) -> Result<ClockDetails<Reference, Output>, Status>
pub fn get_details(&self) -> Result<ClockDetails<Reference, Output>, Status>
Get the clock details, such as backtop time and similar.
This is the same method as on [Clock].