sort per reference key pointer, not on referencepointer itself.
- pidfile: "/etc/unbound/unbound.pid" is now the default.
- tests changed to reflect the updated default.
+ - created hashtable clear() function that respects locks.
30 October 2007: Wouter
- fixup assertion failure that relied on compressed names to be
srandom(48);
for(i=0; i<1000; i++) {
/* what to do? */
+ if(i == 500) {
+ lruhash_clear(table);
+ memset(ref, 0, sizeof(ref));
+ continue;
+ }
switch(random() % 4) {
case 0:
case 3:
srandom(48);
for(i=0; i<1000; i++) {
/* what to do? */
+ if(i == 500) {
+ slabhash_clear(table);
+ memset(ref, 0, sizeof(ref));
+ continue;
+ }
switch(random() % 4) {
case 0:
case 3:
(*table->deldatafunc)(d, table->cb_arg);
}
+/** clear bin, respecting locks, does not do space, LRU */
+static void
+bin_clear(struct lruhash* table, struct lruhash_bin* bin)
+{
+ struct lruhash_entry* p, *np;
+ void *d;
+ lock_quick_lock(&bin->lock);
+ p = bin->overflow_list;
+ while(p) {
+ lock_rw_wrlock(&p->lock);
+ np = p->overflow_next;
+ d = p->data;
+ (*table->delkeyfunc)(p->key, table->cb_arg, 1);
+ (*table->deldatafunc)(d, table->cb_arg);
+ p = np;
+ }
+ bin->overflow_list = NULL;
+ lock_quick_unlock(&bin->lock);
+}
+
+void
+lruhash_clear(struct lruhash* table)
+{
+ size_t i;
+ log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
+ log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
+ if(!table)
+ return;
+
+ lock_quick_lock(&table->lock);
+ for(i=0; i<table->size; i++) {
+ bin_clear(table, &table->array[i]);
+ }
+ table->lru_start = NULL;
+ table->lru_end = NULL;
+ table->num = 0;
+ table->space_used = 0;
+ lock_quick_unlock(&table->lock);
+}
void
lruhash_status(struct lruhash* table, const char* id, int extended)
*/
void lruhash_delete(struct lruhash* table);
+/**
+ * Clear hash table. Entries are all deleted, while locking them before
+ * doing so. At end the table is empty.
+ * @param table: to make empty.
+ */
+void lruhash_clear(struct lruhash* table);
+
/**
* Insert a new element into the hashtable.
* If key is already present data pointer in that entry is updated.
free(sl);
}
+void slabhash_clear(struct slabhash* sl)
+{
+ size_t i;
+ if(!sl)
+ return;
+ for(i=0; i<sl->size; i++)
+ lruhash_clear(sl->array[i]);
+}
+
/** helper routine to calculate the slabhash index */
static unsigned int
slab_idx(struct slabhash* sl, hashvalue_t hash)
*/
void slabhash_delete(struct slabhash* table);
+/**
+ * Clear hash table. Entries are all deleted.
+ * @param table: to make empty.
+ */
+void slabhash_clear(struct slabhash* table);
+
/**
* Insert a new element into the hashtable, uses lruhash_insert.
* If key is already present data pointer in that entry is updated.