v0.4.0

Clocks v0.1.0

Source
Reading clocks and sleeping.

ClockRealtime

pub const ClockRealtime: int32 = 0;

CLOCK_REALTIME: wall-clock time, which can jump when the system clock is set.

Source

ClockMonotonic

pub const ClockMonotonic: int32 = 1;

CLOCK_MONOTONIC: time since an unspecified point, which never goes backwards. Not comparable between boots, and not the clock to record a timestamp with. It is the one to measure a duration with, because setting the system clock cannot affect it.

Source

ClockGetTime

pub unsafe func ClockGetTime(
    clockId: int32,
    time: *var Timespec
) -> int64

Reads clockId into time. clockId is read by value; time is borrowed and written. Returns zero, or a negative error number — EINVAL for a clock this kernel does not have. Safety: time must be non-null and writable.

Source

Parameters

NameTypeDescription
clockIdint32which clock to read
time*var Timespecreceives the reading

Returns: zero, or a negative error number

Nanosleep

pub unsafe func Nanosleep(
    request: *Timespec,
    remaining: *var Timespec
) -> int64

Suspends the caller for the requested duration. request is borrowed and read; remaining is borrowed and written when the wait was cut short, and may be null when the caller does not care. Returns zero, or a negative error number. A signal interrupts the wait and reports EINTR with the unslept time in remaining, which is what makes the second argument worth passing: resuming means calling again with what came back, not with the original request. The wait is against ClockRealtime but is not affected by the clock being set. Safety: request must be non-null and readable, and a non-null remaining must be writable. The nanoseconds of request must be under one second or the call reports EINVAL.

Source

Parameters

NameTypeDescription
request*Timespechow long to wait
remaining*var Timespecreceives the unslept time when a signal cut the wait short, and may be null

Returns: zero, or a negative error number

ClockProcessCpuTime

pub const ClockProcessCpuTime: int32 = 2;

CLOCK_PROCESS_CPUTIME_ID: processor time this process has used.

Source

ClockThreadCpuTime

pub const ClockThreadCpuTime: int32 = 3;

CLOCK_THREAD_CPUTIME_ID: processor time this thread has used.

Source

ClockMonotonicRaw

pub const ClockMonotonicRaw: int32 = 4;

CLOCK_MONOTONIC_RAW: like ClockMonotonic, but not adjusted by time synchronization. Ticks at the hardware's own rate rather than a corrected one, which makes it the wrong clock for measuring a duration anyone will compare against a wall clock, and the right one for measuring the hardware.

Source

TimerAbsolute

pub const TimerAbsolute: int32 = 1;

TIMER_ABSTIME: ClockNanosleep should treat its time as an absolute deadline.

Source

ClockGetResolution

pub unsafe func ClockGetResolution(
    clockId: int32,
    resolution: *var Timespec
) -> int64

Reads the resolution of clockId into resolution. Returns zero, or a negative error number. The resolution is the granularity the clock advances by, which is not the cost of reading it and not a promise about accuracy. Safety: resolution must be non-null and writable.

Source

Parameters

NameTypeDescription
clockIdint32which clock to describe
resolution*var Timespecreceives the granularity

Returns: zero, or a negative error number

ClockNanosleep

pub unsafe func ClockNanosleep(
    clockId: int32,
    flags: int32,
    request: *Timespec,
    remaining: *var Timespec
) -> int64

Suspends the caller against a named clock, optionally until an absolute time. flags is zero for a relative wait or TimerAbsolute for a deadline. remaining is written only for a relative wait that a signal cut short, and may be null. Returns zero, or a positive error number — this one call reports its error positively rather than negatively, which is the kernel's inconsistency and not this binding's. An absolute wait is what a loop should use: a relative wait restarted after a signal drifts, because the time spent handling the signal is not counted. Safety: request must be non-null and readable, and a non-null remaining must be writable.

Source

Parameters

NameTypeDescription
clockIdint32which clock to wait against
flagsint32zero for a relative wait, or TimerAbsolute for a deadline
request*Timespechow long to wait, or when to wake
remaining*var Timespecreceives the unslept time for a relative wait, and may be null

Returns: zero, or a positive error number