From 58411110894c0a9e6a1a1ec9dbdf2fbe2ef3da00 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 21 Aug 2009 16:06:08 +0200 Subject: 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 --- src/date.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/date.c (limited to 'src/date.c') 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 + * + * 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 +#include + +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; +} -- cgit v1.2.3