aboutsummaryrefslogtreecommitdiff
path: root/src/timer.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-10 15:03:43 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-10 17:21:54 +0300
commit8b04169265fb9762b2c1dfca3f43068f5b8233be (patch)
tree43049c1809b2b70b21ed9300ebdd286d18833c8b /src/timer.c
parentbb242e454d5cf8b0c6bb1ca5d009ec18e86c0c2b (diff)
downloadwydawca-8b04169265fb9762b2c1dfca3f43068f5b8233be.tar.gz
wydawca-8b04169265fb9762b2c1dfca3f43068f5b8233be.tar.bz2
Update grecs.
* Makefile.am (ChangeLog): Use git2chg.awk. * bootstrap.conf (gnulib_modules): Don't access grecs/gnulib.modules. * configure.ac (GRECS_SETUP): Add options. * gnulib.modules (getopt,gitlog-to-changelog) (hash,error,version-etc): Remove. * src/Makefile.am: Remove getopt.m4, use one from grecs. * src/getopt.m4: Remove. * src/cmdline.opt: Rewrite. * src/config.c: Update. * src/wydawca.h (spool) <aliases>: Change data type. (all_spool_aliases): Change data type. (config_finish): New proto. * src/wydawca.c: Use grecs functions. * src/dictionary.c: Likewise. * src/net.c: Likewise. * src/process.c: Likewise. * src/mail.c: Use grecs_symtab. * src/timer.c: Likewise. * src/triplet.c: Likewise.
Diffstat (limited to 'src/timer.c')
-rw-r--r--src/timer.c79
1 files changed, 32 insertions, 47 deletions
diff --git a/src/timer.c b/src/timer.c
index bb00e17..71f63f9 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -19,7 +19,6 @@
#include <sys/resource.h>
#include <unistd.h>
#include <string.h>
-#include <hash.h>
#include <ctype.h>
#include <xalloc.h>
@@ -36,11 +35,11 @@ struct timer_slot
struct rusage children_mark;
};
-static Hash_table *timer_table;
+static struct grecs_symtab *timer_table;
static size_t _timer_count;
-static size_t
-hash_string_ci (const char *string, size_t n_buckets)
+static unsigned
+hash_string_ci (const char *string, unsigned long n_buckets)
{
size_t value = 0;
unsigned char ch;
@@ -50,52 +49,38 @@ hash_string_ci (const char *string, size_t n_buckets)
return value;
}
-/* Calculate the hash of a string. */
-static size_t
-timer_hasher (void const *data, unsigned n_buckets)
+static unsigned
+timer_hasher (void *ptr, unsigned long n_buckets)
{
- const struct timer_slot *t = data;
- return hash_string_ci (t->name, n_buckets);
-}
-
-/* Compare two strings for equality. */
-static bool
-timer_compare (void const *data1, void const *data2)
-{
- const struct timer_slot *t1 = data1;
- const struct timer_slot *t2 = data2;
- return strcasecmp (t1->name, t2->name) == 0;
-}
-
-/* Allocate a timer structure */
-static wydawca_timer_t
-timer_alloc (const char *name)
-{
- wydawca_timer_t t = xmalloc (sizeof (*t) + strlen (name) + 1);
- memset (t, 0, sizeof (*t));
- t->name = (char *) (t + 1);
- strcpy (t->name, name);
- return t;
+ struct timer_slot *tp = ptr;
+ return hash_string_ci (tp->name, n_buckets);
}
/* Lookup a timer by its name. If it does not exist, create it. */
wydawca_timer_t
timer_get (const char *name)
{
- wydawca_timer_t tp, ret;
-
- tp = timer_alloc (name);
+ struct timer_slot key, *ret;
+ int install = 1;
+
+ key.name = (char*) name;
- if (!((timer_table
- || (timer_table = hash_initialize (0, 0,
- timer_hasher,
- timer_compare, 0)))
- && (ret = hash_insert (timer_table, tp))))
- xalloc_die ();
+ if (!timer_table)
+ {
+ timer_table = grecs_symtab_create (sizeof (key),
+ timer_hasher,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ if (!timer_table)
+ grecs_alloc_die ();
+ }
- if (ret != tp)
- free (tp);
- else
+ ret = grecs_symtab_lookup_or_install (timer_table, &key, &install);
+ if (!ret)
+ grecs_alloc_die();
+ if (install)
_timer_count++;
return ret;
}
@@ -210,11 +195,11 @@ struct timer_data
size_t num;
};
-bool
-_fill_meta (void *data, void *proc_data)
+int
+_fill_meta (void *sym, void *data)
{
- struct timer_slot *slot = data;
- struct timer_data *tp = proc_data;
+ struct timer_slot *slot = sym;
+ struct timer_data *tp = data;
#define CREATE_DEF(arg) \
if (tp->num) \
{ \
@@ -230,7 +215,7 @@ _fill_meta (void *data, void *proc_data)
CREATE_DEF(real);
CREATE_DEF(user);
- return tp->num > 0;
+ return tp->num <= 0;
}
void
@@ -241,7 +226,7 @@ timer_fill_meta (struct metadef *def, size_t num)
return;
td.def = def;
td.num = num;
- hash_do_for_each (timer_table, _fill_meta, &td);
+ grecs_symtab_enumerate (timer_table, _fill_meta, &td);
}
void

Return to:

Send suggestions and report system problems to the System administrator.