use time_monotonic() instead of gettimeofday() for time difference calculations

This commit is contained in:
Martin Willi
2009-08-31 15:25:03 +02:00
parent 3d5818ec38
commit de5784452b
9 changed files with 24 additions and 37 deletions
@@ -20,7 +20,6 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <stdint.h>
#include <linux/ipsec.h>
#include <linux/netlink.h>
@@ -17,7 +17,6 @@
#include <sys/socket.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <sys/time.h>
#include <pthread.h>
#include <unistd.h>
#include <errno.h>
@@ -145,7 +144,7 @@ struct private_kernel_netlink_net_t {
/**
* time of the last roam_job
*/
struct timeval last_roam;
timeval_t last_roam;
/**
* routing table to install routes
@@ -208,22 +207,20 @@ static int get_vip_refcount(private_kernel_netlink_net_t *this, host_t* ip)
*/
static void fire_roam_job(private_kernel_netlink_net_t *this, bool address)
{
struct timeval now;
timeval_t now;
if (gettimeofday(&now, NULL) == 0)
time_monotonic(&now);
if (timercmp(&now, &this->last_roam, >))
{
if (timercmp(&now, &this->last_roam, >))
now.tv_usec += ROAM_DELAY * 1000;
while (now.tv_usec > 1000000)
{
now.tv_usec += ROAM_DELAY * 1000;
while (now.tv_usec > 1000000)
{
now.tv_sec++;
now.tv_usec -= 1000000;
}
this->last_roam = now;
charon->scheduler->schedule_job_ms(charon->scheduler,
(job_t*)roam_job_create(address), ROAM_DELAY);
now.tv_sec++;
now.tv_usec -= 1000000;
}
this->last_roam = now;
charon->scheduler->schedule_job_ms(charon->scheduler,
(job_t*)roam_job_create(address), ROAM_DELAY);
}
}