summaryrefslogtreecommitdiff
path: root/src/alarm.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2009-08-21 16:06:08 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2009-08-21 16:06:08 +0200
commit58411110894c0a9e6a1a1ec9dbdf2fbe2ef3da00 (patch)
tree384477cd9a167103eedde5d0b0993cd1ac927092 /src/alarm.c
parent3e6852f806c4368eda451b39f12b2ac2f2b5d33b (diff)
downloadconntrack-tools-58411110894c0a9e6a1a1ec9dbdf2fbe2ef3da00.tar.gz
conntrack-tools-58411110894c0a9e6a1a1ec9dbdf2fbe2ef3da00.zip
conntrackd: reduce the number of gettimeofday() syscalls
This patch reduces the number of gettimeofday syscalls by caching the current time in a variable at the beginning of the main loop. Based on a suggestion from Vincent Jardin. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/alarm.c')
-rw-r--r--src/alarm.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/alarm.c b/src/alarm.c
index fe938a0..006721a 100644
--- a/src/alarm.c
+++ b/src/alarm.c
@@ -17,6 +17,7 @@
*/
#include "alarm.h"
+#include "date.h"
#include <stdlib.h>
#include <limits.h>
@@ -61,7 +62,7 @@ void add_alarm(struct alarm_block *alarm, unsigned long sc, unsigned long usc)
del_alarm(alarm);
alarm->tv.tv_sec = sc;
alarm->tv.tv_usec = usc;
- gettimeofday(&tv, NULL);
+ gettimeofday_cached(&tv);
timeradd(&alarm->tv, &tv, &alarm->tv);
__add_alarm(alarm);
}
@@ -107,7 +108,7 @@ get_next_alarm_run(struct timeval *next_run)
struct rb_node *node;
struct timeval tv;
- gettimeofday(&tv, NULL);
+ gettimeofday_cached(&tv);
node = rb_first(&alarm_root);
if (node) {
@@ -126,7 +127,7 @@ do_alarm_run(struct timeval *next_run)
struct alarm_block *this, *tmp;
struct timeval tv;
- gettimeofday(&tv, NULL);
+ gettimeofday_cached(&tv);
INIT_LIST_HEAD(&alarm_run_queue);
for (node = rb_first(&alarm_root); node; node = rb_next(node)) {