From 16a678004a5aa6afafddc55bda1d05bfb0e8db22 Mon Sep 17 00:00:00 2001 From: reinelt Date: Wed, 21 Jan 2004 10:48:17 +0000 Subject: [lcd4linux @ 2004-01-21 10:48:17 by reinelt] hash_age function added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@329 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- plugin_proc_stat.c | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'plugin_proc_stat.c') diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c index 52c0ad6..d7d56c8 100644 --- a/plugin_proc_stat.c +++ b/plugin_proc_stat.c @@ -1,4 +1,4 @@ -/* $Id: plugin_proc_stat.c,v 1.6 2004/01/20 12:45:47 reinelt Exp $ +/* $Id: plugin_proc_stat.c,v 1.7 2004/01/21 10:48:17 reinelt Exp $ * * plugin for /proc/stat parsing * @@ -23,6 +23,9 @@ * * * $Log: plugin_proc_stat.c,v $ + * Revision 1.7 2004/01/21 10:48:17 reinelt + * hash_age function added + * * Revision 1.6 2004/01/20 12:45:47 reinelt * "Default screen" working with MatrixOrbital * @@ -63,36 +66,13 @@ #include #include #include -#include -#include #include "debug.h" #include "plugin.h" #include "hash.h" -static HASH Stat = { 0, 0, NULL }; - - -static int renew(int msec) -{ - static struct timeval end = {0, 0}; - struct timeval now; - - // update every 10 msec - gettimeofday(&now, NULL); - if (now.tv_sec==end.tv_sec?now.tv_usec 1000000) { - end.tv_usec -= 1000000; - end.tv_sec++; - } - return 1; -} - +static HASH Stat = { 0, }; static void hash_set1 (char *key1, char *val) { @@ -122,8 +102,9 @@ static int parse_proc_stat (void) { FILE *stream; - // update every 10 msec - if (!renew(10)) return 0; + // reread every 10 msec only + age=hash_age(&Stat, NULL, NULL); + if (age>0 && age<=10) return 0; stream=fopen("/proc/stat", "r"); if (stream==NULL) { -- cgit v1.2.3