]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
lruhash remove routine.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 14 Mar 2007 12:21:03 +0000 (12:21 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 14 Mar 2007 12:21:03 +0000 (12:21 +0000)
git-svn-id: file:///svn/unbound/trunk@178 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
util/storage/lruhash.c
util/storage/lruhash.h

index fcda773a224a98da959feea3766e68e2ec4eb264..ff622daec7a56c4ca57802003ef0ba56774c261d 100644 (file)
@@ -1,5 +1,6 @@
 14 March 2007: Wouter
        - hash table insert (and subroutines) and lookup implemented.
+       - hash table remove.
 
 13 March 2007: Wouter
        - lock_unprotect in checklocks.
index de6fc7aa1eb8d7d74d9f74b6a4e611077fd52b85..e173a5f98a6cefe1ba783d3e7b5c4bd242844bbd 100644 (file)
@@ -138,10 +138,10 @@ bin_init(struct lruhash_bin* array, size_t size)
        }
 }
 
-struct lruhash* lruhash_create(size_t start_size, size_t maxmem,
-        lruhash_sizefunc_t sizefunc, lruhash_compfunc_t compfunc,
-       lruhash_delkeyfunc_t delkeyfunc, lruhash_deldatafunc_t deldatafunc,
-       void* arg)
+struct lruhash* 
+lruhash_create(size_t start_size, size_t maxmem, lruhash_sizefunc_t sizefunc, 
+       lruhash_compfunc_t compfunc, lruhash_delkeyfunc_t delkeyfunc, 
+       lruhash_deldatafunc_t deldatafunc, void* arg)
 {
        struct lruhash* table = (struct lruhash*)calloc(1, 
                sizeof(struct lruhash));
@@ -173,7 +173,8 @@ struct lruhash* lruhash_create(size_t start_size, size_t maxmem,
        return table;
 }
 
-static void bin_delete(struct lruhash* table, struct lruhash_bin* bin)
+static void 
+bin_delete(struct lruhash* table, struct lruhash_bin* bin)
 {
        struct lruhash_entry* p, *np;
        if(!bin)
@@ -217,7 +218,8 @@ bin_split(struct lruhash* table, struct lruhash_bin* newa,
        }
 }
 
-void lruhash_delete(struct lruhash* table)
+void 
+lruhash_delete(struct lruhash* table)
 {
        size_t i;
        if(!table)
@@ -361,7 +363,8 @@ lru_touch(struct lruhash* table, struct lruhash_entry* entry)
        lru_front(table, entry);
 }
 
-void lruhash_insert(struct lruhash* table, hashvalue_t hash,
+void 
+lruhash_insert(struct lruhash* table, hashvalue_t hash,
         struct lruhash_entry* entry, void* data)
 {
        struct lruhash_bin* bin;
@@ -408,10 +411,10 @@ void lruhash_insert(struct lruhash* table, hashvalue_t hash,
        }
 }
 
-struct lruhash_entry* lruhash_lookup(struct lruhash* table, hashvalue_t hash,
-       void* key, int wr)
+struct lruhash_entry* 
+lruhash_lookup(struct lruhash* table, hashvalue_t hash, void* key, int wr)
 {
-       struct lruhash_entry* entry = NULL;
+       struct lruhash_entry* entry;
        struct lruhash_bin* bin;
 
        lock_quick_lock(&table->lock);
@@ -430,6 +433,28 @@ struct lruhash_entry* lruhash_lookup(struct lruhash* table, hashvalue_t hash,
        return entry;
 }
 
-void lruhash_remove(struct lruhash* table, void* key)
+void 
+lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key)
 {
+       struct lruhash_entry* entry;
+       struct lruhash_bin* bin;
+
+       lock_quick_lock(&table->lock);
+       bin = &table->array[hash & table->size_mask];
+       lock_quick_lock(&bin->lock);
+       if((entry=bin_find_entry(table, bin, hash, key))) {
+               bin_overflow_remove(bin, entry);
+               lru_remove(table, entry);
+       } else {
+               lock_quick_unlock(&table->lock);
+               lock_quick_unlock(&bin->lock);
+               return;
+       }
+       lock_quick_unlock(&table->lock);
+       lock_rw_wrlock(&entry->lock);
+       lock_quick_unlock(&bin->lock);
+       /* finish removal */
+       lock_rw_unlock(&entry->lock);
+       (*table->delkeyfunc)(entry->key, table->cb_arg);
+       (*table->deldatafunc)(entry->data, table->cb_arg);
 }
index 8fd8da7eb54503c35224b8e731c9a6a4f3926e94..f4397bac70fed94d91c06c20ddbe8379b0d12985 100644 (file)
@@ -270,8 +270,9 @@ struct lruhash_entry* lruhash_lookup(struct lruhash* table, hashvalue_t hash,
  * Remove entry from hashtable. Does nothing if not found in hashtable.
  * Delfunc is called for the entry.
  * @param table: hash table.
+ * @param hash: hash of key.
  * @param key: what to look for. 
  */
-void lruhash_remove(struct lruhash* table, void* key);
+void lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key);
 
 #endif /* UTIL_STORAGE_LRUHASH_H */