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 = 6;

CLOCK_MONOTONIC: time since boot, which never goes backwards. Darwin numbers this 6, where Linux uses 1 and FreeBSD uses 4. No clock identifier means the same thing on any two of the three systems.

Source

ClockMonotonicRaw

pub const ClockMonotonicRaw: int32 = 4;

CLOCK_MONOTONIC_RAW: like ClockMonotonic, but not adjusted by time synchronization.

Source

ClockGetTime

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

Reads clockId into time. Callers pass an explicit address, as they do on Linux and FreeBSD: ClockGetTime(ClockMonotonic, @time). The call itself needs macOS 10.12 or later; an older release has no such symbol and the program will not launch. time must be non-null and writable for a whole Timespec.

Source

Parameters

NameTypeDescription
clockIdint32which clock to read, one of the identifiers above
time*var Timespecreceives the reading

Returns: zero, or a negative error number

ClockGetResolution

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

Reads the resolution of clockId into resolution. The resolution is the granularity the clock advances by, not the cost of reading it and not a promise about accuracy. Like ClockGetTime, it needs macOS 10.12 or later. resolution must be non-null and writable for a whole Timespec.

Source

Parameters

NameTypeDescription
clockIdint32which clock to describe, one of the identifiers above
resolution*var Timespecreceives the granularity

Returns: zero, or a negative error number

GetTimeOfDay

pub func GetTimeOfDay(time: *var Timeval) -> int64

Reads the wall clock into time, to microsecond resolution. The second argument of the underlying call is an obsolete time-zone output that this passes as null. Timeval has Darwin's layout: an eight-byte second count and a four-byte microsecond count, not two 64-bit fields. time must be non-null and writable for a whole Timeval.

Source

Parameters

NameTypeDescription
time*var Timevalreceives the reading

Returns: zero, or a negative error number

Nanosleep

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

Suspends the caller for the requested duration. EINTR with the unslept time left in remaining is how a signal cutting the wait short is reported. request must be non-null, and its nanoseconds must be under one second.

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