Be a little more paranoid about initialization.
authoraland <aland>
Tue, 22 Aug 2006 23:02:15 +0000 (23:02 +0000)
committeraland <aland>
Tue, 22 Aug 2006 23:02:15 +0000 (23:02 +0000)
src/lib/dict.c
src/lib/hash.c

index 45bdf06..c3f06b4 100644 (file)
@@ -1279,6 +1279,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.
@@ -1413,6 +1426,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;
 }
 
index f4cec24..2bae77f 100644 (file)
@@ -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;