Use a helper function to add milliseconds to timeval structs
This commit is contained in:
@@ -282,13 +282,7 @@ METHOD(condvar_t, timed_wait, bool,
|
||||
ms = timeout % 1000;
|
||||
|
||||
tv.tv_sec += s;
|
||||
tv.tv_usec += ms * 1000;
|
||||
|
||||
if (tv.tv_usec > 1000000 /* 1s */)
|
||||
{
|
||||
tv.tv_usec -= 1000000;
|
||||
tv.tv_sec++;
|
||||
}
|
||||
timeval_add_ms(&tv, ms);
|
||||
return timed_wait_abs(this, mutex, tv);
|
||||
}
|
||||
|
||||
|
||||
@@ -433,13 +433,8 @@ METHOD(rwlock_condvar_t, timed_wait, bool,
|
||||
ms = timeout % 1000;
|
||||
|
||||
tv.tv_sec += s;
|
||||
tv.tv_usec += ms * 1000;
|
||||
timeval_add_ms(&tv, ms);
|
||||
|
||||
if (tv.tv_usec > 1000000 /* 1s */)
|
||||
{
|
||||
tv.tv_usec -= 1000000;
|
||||
tv.tv_sec++;
|
||||
}
|
||||
return timed_wait_abs(this, lock, tv);
|
||||
}
|
||||
|
||||
|
||||
@@ -454,6 +454,22 @@ void closefrom(int lowfd);
|
||||
*/
|
||||
time_t time_monotonic(timeval_t *tv);
|
||||
|
||||
/**
|
||||
* Add the given number of milliseconds to the given timeval struct
|
||||
*
|
||||
* @param tv timeval struct to modify
|
||||
* @param ms number of milliseconds
|
||||
*/
|
||||
static inline void timeval_add_ms(timeval_t *tv, u_int ms)
|
||||
{
|
||||
tv->tv_usec += ms * 1000;
|
||||
while (tv->tv_usec > 1000000 /* 1s */)
|
||||
{
|
||||
tv->tv_usec -= 1000000;
|
||||
tv->tv_sec++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns null
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user