From: Jouni Malinen Date: Wed, 14 Feb 2024 19:42:35 +0000 (+0200) Subject: Add os_reltime helpers to work with milliseconds X-Git-Tag: hostap_2_11~373 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f557c5947cf1a45c1fe828ecb6728e0a95ac293;p=thirdparty%2Fhostap.git Add os_reltime helpers to work with milliseconds Signed-off-by: Jouni Malinen --- diff --git a/src/utils/os.h b/src/utils/os.h index 07abf7a9a0..1bbaea3a4b 100644 --- a/src/utils/os.h +++ b/src/utils/os.h @@ -108,6 +108,26 @@ static inline int os_reltime_expired(struct os_reltime *now, } +static inline void os_reltime_add_ms(struct os_reltime *ts, int ms) +{ + ts->usec += ms * 1000; + while (ts->usec >= 1000000) { + ts->sec++; + ts->usec -= 1000000; + } + while (ts->usec < 0) { + ts->sec--; + ts->usec += 1000000; + } +} + + +static inline int os_reltime_in_ms(struct os_reltime *ts) +{ + return ts->sec * 1000 + ts->usec / 1000; +} + + static inline int os_reltime_initialized(struct os_reltime *t) { return t->sec != 0 || t->usec != 0;