Add os_reltime helpers to work with milliseconds
Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
This commit is contained in:
parent
0b5d370c00
commit
4f557c5947
1 changed files with 20 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue