mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
hash clear function.
git-svn-id: file:///svn/unbound/trunk@725 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
f79c387f3f
commit
2725ad55fc
7 changed files with 72 additions and 0 deletions
|
|
@ -9,6 +9,7 @@
|
|||
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
|
||||
|
|
|
|||
|
|
@ -371,6 +371,11 @@ test_long_table(struct lruhash* table)
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -251,6 +251,11 @@ test_long_table(struct slabhash* table)
|
|||
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:
|
||||
|
|
|
|||
|
|
@ -402,6 +402,45 @@ lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key)
|
|||
(*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)
|
||||
|
|
|
|||
|
|
@ -243,6 +243,13 @@ struct lruhash* lruhash_create(size_t start_size, size_t maxmem,
|
|||
*/
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -97,6 +97,15 @@ void slabhash_delete(struct slabhash* sl)
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -90,6 +90,12 @@ struct slabhash* slabhash_create(size_t numtables, size_t start_size,
|
|||
*/
|
||||
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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue