From 2ae9b154778b565c17f8b148773b799b88a7c1d5 Mon Sep 17 00:00:00 2001 From: aland Date: Tue, 22 Aug 2006 23:02:36 +0000 Subject: [PATCH] Be a little more paranoid about initialization. --- src/lib/dict.c | 28 ++++++++++++++++++++++++++++ src/lib/hash.c | 7 +++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/lib/dict.c b/src/lib/dict.c index 4f5f179ccf..e476f77eea 100644 --- a/src/lib/dict.c +++ b/src/lib/dict.c @@ -1111,6 +1111,19 @@ static int my_dict_init(const char *dir, const char *fn, return 0; } + +/* + * Empty callback for hash table initialization. + */ +static int null_callback(void *ctx, void *data) +{ + ctx = ctx; /* -Wunused */ + data = data; /* -Wunused */ + + return 0; +} + + /* * Initialize the directory, then fix the attr member of * all attributes. @@ -1245,6 +1258,21 @@ int dict_init(const char *dir, const char *fn) } } + /* + * Walk over all of the hash tables to ensure they're + * initialized. We do this because the threads may perform + * lookups, and we don't want multi-threaded re-ordering + * of the table entries. That would be bad. + */ + lrad_hash_table_walk(vendors_byname, null_callback, NULL); + lrad_hash_table_walk(vendors_byvalue, null_callback, NULL); + + lrad_hash_table_walk(attributes_byname, null_callback, NULL); + lrad_hash_table_walk(attributes_byvalue, null_callback, NULL); + + lrad_hash_table_walk(values_byvalue, null_callback, NULL); + lrad_hash_table_walk(values_byname, null_callback, NULL); + return 0; } diff --git a/src/lib/hash.c b/src/lib/hash.c index bd098a5955..2c3b257156 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -594,10 +594,13 @@ int lrad_hash_table_walk(lrad_hash_table_t *ht, if (!ht || !callback) return 0; - for (i = 0; i < ht->num_buckets; i++) { + for (i = ht->num_buckets - 1; i >= 0; i--) { lrad_hash_entry_t *node, *next; - if (!ht->buckets[i]) continue; + /* + * Ensure that the current bucket is filled. + */ + if (!ht->buckets[i]) lrad_hash_table_fixup(ht, i); for (node = ht->buckets[i]; node != &ht->null; node = next) { next = node->next; -- 2.47.3