Skip to main content

MappedClock

Struct MappedClock 

Source
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>

Source

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 least zx::VmarFlags::PERM_READ.
§Errors

The conversion may fail if clock was not created as a mappable clock using [ClockOpts::MAPPABLE] at its creation time.

Source

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 include SPECIFIC if offset is not zero.
Source

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.

Source

pub fn raw_addr(&self) -> usize

Returns the raw value of the address this clock is mapped to.

Source

pub fn size(&self) -> usize

The size of the memory region occupied by this memory mapped clock.

Source

pub fn read(&self) -> Result<Instant<Output>, Status>

Read the clock indication.

This is the same method as on [Clock].

Source

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].

Trait Implementations§

Source§

impl<Reference: Debug + Timeline, Output: Debug + Timeline> Debug for MappedClock<Reference, Output>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Reference: Timeline, Output: Timeline> Drop for MappedClock<Reference, Output>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<Reference, Output> Freeze for MappedClock<Reference, Output>

§

impl<Reference, Output> RefUnwindSafe for MappedClock<Reference, Output>
where Reference: RefUnwindSafe, Output: RefUnwindSafe,

§

impl<Reference, Output> Send for MappedClock<Reference, Output>
where Reference: Send, Output: Send,

§

impl<Reference, Output> Sync for MappedClock<Reference, Output>
where Reference: Sync, Output: Sync,

§

impl<Reference, Output> Unpin for MappedClock<Reference, Output>
where Reference: Unpin, Output: Unpin,

§

impl<Reference, Output> UnsafeUnpin for MappedClock<Reference, Output>

§

impl<Reference, Output> UnwindSafe for MappedClock<Reference, Output>
where Reference: UnwindSafe, Output: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.