kernel/timeout: Add absolute timeout APIs

Add support for "absolute" timeouts, which are expressed relative to
system uptime instead of deltas from current time.  These allow for
more race-resistant code to be written by allowing application code to
do a single timeout computation, once, and then reuse the timeout
value even if the thread wakes up and needs to suspend again later.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
Andy Ross 2020-03-09 09:35:35 -07:00 committed by Anas Nashif
commit 4c7b77a716
6 changed files with 106 additions and 8 deletions

View file

@ -1606,6 +1606,32 @@ const char *k_thread_state_str(k_tid_t thread_id);
*/
#define K_FOREVER Z_FOREVER
/**
* @brief Generates an absolute/uptime timeout value in ticks
*
* This macro generates a timeout delay that represents an expiration
* at the absolute uptime value specified, in ticks. That is, the
* timeout will expire immediately after the system uptime reaches the
* specified tick count.
*
* @param t Tick uptime value
* @return Timeout delay value
*/
#define K_TIMEOUT_ABS_TICKS(t) Z_TIMEOUT_TICKS(Z_TICK_ABS(MAX(t, 0)))
/**
* @brief Generates an absolute/uptime timeout value in ms
*
* This macro generates a timeout delay that represents an expiration
* at the absolute uptime value specified, in milliseconds. That is,
* the timeout will expire immediately after the system uptime reaches
* the specified tick count.
*
* @param t Millisecond uptime value
* @return Timeout delay value
*/
#define K_TIMEOUT_ABS_MS(t) K_TIMEOUT_ABS_TICKS(k_ms_to_ticks_ceil64(t))
/**
* @}
*/