summaryrefslogtreecommitdiffstats
path: root/src/date.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/date.c
parent3e6852f806c4368eda451b39f12b2ac2f2b5d33b (diff)
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/date.c')
-rw-r--r--src/date.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/date.c b/src/date.c
new file mode 100644
index 0000000..f5a5ada
--- /dev/null
+++ b/src/date.c
@@ -0,0 +1,28 @@
+/*
+ * (C) 2009 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+#include "date.h"
+#include <stdlib.h>
+#include <string.h>
+
+static struct timeval now;
+
+int do_gettimeofday(void)
+{
+ return gettimeofday(&now, NULL);
+}
+
+void gettimeofday_cached(struct timeval *tv)
+{
+ memcpy(tv, &now, sizeof(struct timeval));
+}
+
+int time_cached(void)
+{
+ return now.tv_sec;
+}