SolarCapture C Bindings User Guide  SF-115721-CD
Issue 3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
time.h File Reference

Functions for managing time. More...

Functions

void sc_timer_expire_at (struct sc_callback *cb, const struct timespec *time)
 Request a callback at a given time. More...
 
void sc_timer_expire_after_ns (struct sc_callback *cb, int64_t delta_ns)
 Request a callback in the future. More...
 
void sc_timer_push_back_ns (struct sc_callback *cb, int64_t delta_ns)
 Push the expiry time further into the future. More...
 
int sc_timer_get_expiry_time (const struct sc_callback *cb, struct timespec *ts_out)
 Return the expiry time of a timer callback. More...
 
static uint64_t sc_ns_from_ts (const struct timespec *ts)
 Convert a timespec struct to nanoseconds. More...
 
static uint64_t sc_ns_from_tv (const struct timeval *tv)
 Convert a timeval struct to nanoseconds. More...
 
static uint64_t sc_ns_from_ms (uint64_t ms)
 Convert milliseconds to nanoseconds. More...
 
static uint64_t sc_ns_from_us (uint64_t us)
 Convert microseconds to nanoseconds. More...
 

Detailed Description

Functions for managing time.

Function Documentation

static uint64_t sc_ns_from_ms ( uint64_t  ms)
inlinestatic

Convert milliseconds to nanoseconds.

Parameters
msThe time in milliseconds to convert
Returns
Time in nanoseconds
static uint64_t sc_ns_from_ts ( const struct timespec *  ts)
inlinestatic

Convert a timespec struct to nanoseconds.

Parameters
tsThe timespec struct to convert
Returns
Time in nanoseconds
static uint64_t sc_ns_from_tv ( const struct timeval *  tv)
inlinestatic

Convert a timeval struct to nanoseconds.

Parameters
tvThe timeval struct to convert
Returns
Time in nanoseconds
static uint64_t sc_ns_from_us ( uint64_t  us)
inlinestatic

Convert microseconds to nanoseconds.

Parameters
usThe time in microseconds to convert
Returns
Time in nanoseconds
void sc_timer_expire_after_ns ( struct sc_callback cb,
int64_t  delta_ns 
)

Request a callback in the future.

Parameters
cbA callback object
delta_nsHow far in the future in nanoseconds.

The callback will be invoked at or after the specified time delta in nanoseconds. If delta_ns is zero or negative then the handler function will be invoked as soon as possible.

void sc_timer_expire_at ( struct sc_callback cb,
const struct timespec *  time 
)

Request a callback at a given time.

Parameters
cbA callback object
timeTime at which callback is requested

The callback cb will be invoked at or after the specified time. If the time is in the past, then the handler function will be invoked as soon as possible.

The time is relative to the system realtime clock (CLOCK_REALTIME), which is the same clock returned by sc_thread_get_time().

int sc_timer_get_expiry_time ( const struct sc_callback cb,
struct timespec *  ts_out 
)

Return the expiry time of a timer callback.

Parameters
cbA callback object
ts_outThe expiry time is returned here
Returns
Zero if cb is a timer else -1
void sc_timer_push_back_ns ( struct sc_callback cb,
int64_t  delta_ns 
)

Push the expiry time further into the future.

Parameters
cbA callback object
delta_nsHow far in the future in nanoseconds.

This function pushes the expiry time of a timer callback further into the future.

The callback cb must either be a currently active timer registered with sc_timer_expire_at() or sc_timer_expire_after_ns(), or it must be an inactive timer. ie. The most recent use of cb must have been as a timer callback.

If cb is active, then it is rescheduled at its current expiry time plus delta_ns. If it is not active then it is scheduled at its previous expiry time plus delta_ns.