Add os_reltime helpers to work with milliseconds

Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
This commit is contained in:
Jouni Malinen 2024-02-14 21:42:35 +02:00 committed by Jouni Malinen
parent 0b5d370c00
commit 4f557c5947

View file

@ -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) static inline int os_reltime_initialized(struct os_reltime *t)
{ {
return t->sec != 0 || t->usec != 0; return t->sec != 0 || t->usec != 0;