mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-06-09 08:34:02 -04:00
fptrwlist and remove oldhack with islocked param.
git-svn-id: file:///svn/unbound/trunk@805 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
2dbc83d5ae
commit
f187e1da7e
17 changed files with 48 additions and 44 deletions
|
|
@ -18,6 +18,8 @@
|
|||
- check return value of evtimer_add().
|
||||
- fixup lockorder in lruhash_reclaim(), building up a list of locked
|
||||
entries one at a time. Instead they are removed and unlocked.
|
||||
- fptr_wlist for markdelfunc.
|
||||
- removed is_locked param from lruhash delkeyfunc.
|
||||
|
||||
3 December 2007: Wouter
|
||||
- changed checkconf/ to smallapp/ to make room for more support tools.
|
||||
|
|
|
|||
6
services/cache/infra.c
vendored
6
services/cache/infra.c
vendored
|
|
@ -64,12 +64,11 @@ infra_host_compfunc(void* key1, void* key2)
|
|||
}
|
||||
|
||||
void
|
||||
infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
|
||||
infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
struct infra_host_key* key = (struct infra_host_key*)k;
|
||||
if(!key)
|
||||
return;
|
||||
if(il) { lock_rw_unlock(&key->entry.lock); }
|
||||
lock_rw_destroy(&key->entry.lock);
|
||||
free(key);
|
||||
}
|
||||
|
|
@ -309,12 +308,11 @@ infra_lame_compfunc(void* key1, void* key2)
|
|||
}
|
||||
|
||||
void
|
||||
infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
|
||||
infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
struct infra_lame_key* key = (struct infra_lame_key*)k;
|
||||
if(!key)
|
||||
return;
|
||||
if(il) { lock_rw_unlock(&key->entry.lock); }
|
||||
lock_rw_destroy(&key->entry.lock);
|
||||
free(key->zonename);
|
||||
free(key);
|
||||
|
|
|
|||
4
services/cache/infra.h
vendored
4
services/cache/infra.h
vendored
|
|
@ -267,7 +267,7 @@ size_t infra_host_sizefunc(void* k, void* d);
|
|||
int infra_host_compfunc(void* key1, void* key2);
|
||||
|
||||
/** delete key, and destroy the lock */
|
||||
void infra_host_delkeyfunc(void* k, void* arg, int il);
|
||||
void infra_host_delkeyfunc(void* k, void* arg);
|
||||
|
||||
/** delete data and destroy the lameness hashtable */
|
||||
void infra_host_deldatafunc(void* d, void* arg);
|
||||
|
|
@ -280,7 +280,7 @@ size_t infra_lame_sizefunc(void* k, void* d);
|
|||
int infra_lame_compfunc(void* key1, void* key2);
|
||||
|
||||
/** free key, lock and zonename */
|
||||
void infra_lame_delkeyfunc(void* k, void* arg, int il);
|
||||
void infra_lame_delkeyfunc(void* k, void* arg);
|
||||
|
||||
/** free the lameness data */
|
||||
void infra_lame_deldatafunc(void* d, void* arg);
|
||||
|
|
|
|||
3
services/cache/rrset.c
vendored
3
services/cache/rrset.c
vendored
|
|
@ -47,8 +47,7 @@
|
|||
#include "util/regional.h"
|
||||
#include "util/alloc.h"
|
||||
|
||||
/** mark rrset to be deleted */
|
||||
static void
|
||||
void
|
||||
rrset_markdel(void* key)
|
||||
{
|
||||
struct ub_packed_rrset_key* r = (struct ub_packed_rrset_key*)key;
|
||||
|
|
|
|||
3
services/cache/rrset.h
vendored
3
services/cache/rrset.h
vendored
|
|
@ -207,4 +207,7 @@ void rrset_update_sec_status(struct rrset_cache* r,
|
|||
void rrset_check_sec_status(struct rrset_cache* r,
|
||||
struct ub_packed_rrset_key* rrset);
|
||||
|
||||
/** mark rrset to be deleted, set id=0 */
|
||||
void rrset_markdel(void* key);
|
||||
|
||||
#endif /* SERVICES_CACHE_RRSET_H */
|
||||
|
|
|
|||
|
|
@ -543,12 +543,9 @@ msgreply_sizefunc(void* k, void* d)
|
|||
}
|
||||
|
||||
void
|
||||
query_entry_delete(void *k, void* ATTR_UNUSED(arg), int is_locked)
|
||||
query_entry_delete(void *k, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
struct msgreply_entry* q = (struct msgreply_entry*)k;
|
||||
if(is_locked) {
|
||||
lock_rw_unlock(&q->entry.lock);
|
||||
}
|
||||
lock_rw_destroy(&q->entry.lock);
|
||||
query_info_clear(&q->key);
|
||||
free(q);
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ void query_info_clear(struct query_info* m);
|
|||
size_t msgreply_sizefunc(void* k, void* d);
|
||||
|
||||
/** delete msgreply_entry key structure */
|
||||
void query_entry_delete(void *q, void* arg, int is_locked);
|
||||
void query_entry_delete(void *q, void* arg);
|
||||
|
||||
/** delete reply_info data structure */
|
||||
void reply_info_delete(void* d, void* arg);
|
||||
|
|
|
|||
|
|
@ -121,14 +121,11 @@ ub_rrset_compare(void* k1, void* k2)
|
|||
}
|
||||
|
||||
void
|
||||
ub_rrset_key_delete(void* key, void* userdata, int is_locked)
|
||||
ub_rrset_key_delete(void* key, void* userdata)
|
||||
{
|
||||
struct ub_packed_rrset_key* k = (struct ub_packed_rrset_key*)key;
|
||||
struct alloc_cache* a = (struct alloc_cache*)userdata;
|
||||
k->id = 0;
|
||||
if(is_locked) {
|
||||
lock_rw_unlock(&k->entry.lock);
|
||||
}
|
||||
free(k->rk.dname);
|
||||
k->rk.dname = NULL;
|
||||
alloc_special_release(a, k);
|
||||
|
|
|
|||
|
|
@ -300,13 +300,12 @@ int rrsetdata_equal(struct packed_rrset_data* d1, struct packed_rrset_data* d2);
|
|||
|
||||
/**
|
||||
* Old key to be deleted. RRset keys are recycled via alloc.
|
||||
* The id is set to 0. So that other threads, after acquiring a lock always
|
||||
* get the correct value, in this case the 0 deleted-special value.
|
||||
* @param key: struct ub_packed_rrset_key*.
|
||||
* @param userdata: alloc structure to use for recycling.
|
||||
* @param is_locked: if the key is locked, the id is set to 0 while it is
|
||||
* still locked. So that other threads, after acquiring a lock always
|
||||
* get the correct value, in this case the 0 deleted-special value.
|
||||
*/
|
||||
void ub_rrset_key_delete(void* key, void* userdata, int is_locked);
|
||||
void ub_rrset_key_delete(void* key, void* userdata);
|
||||
|
||||
/**
|
||||
* Old data to be deleted.
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@
|
|||
#include "services/mesh.h"
|
||||
#include "services/localzone.h"
|
||||
#include "services/cache/infra.h"
|
||||
#include "services/cache/rrset.h"
|
||||
#include "iterator/iterator.h"
|
||||
#include "iterator/iter_donotq.h"
|
||||
#include "iterator/iter_fwd.h"
|
||||
|
|
@ -197,6 +198,14 @@ fptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_t fptr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_t fptr)
|
||||
{
|
||||
if(fptr == NULL) return 1;
|
||||
else if(fptr == &rrset_markdel) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
fptr_whitelist_modenv_send_packet(int (*fptr)(ldns_buffer* pkt,
|
||||
struct sockaddr_storage* addr, socklen_t addrlen, int timeout,
|
||||
|
|
|
|||
|
|
@ -155,6 +155,14 @@ int fptr_whitelist_hash_delkeyfunc(lruhash_delkeyfunc_t fptr);
|
|||
*/
|
||||
int fptr_whitelist_hash_deldatafunc(lruhash_deldatafunc_t fptr);
|
||||
|
||||
/**
|
||||
* Check function pointer whitelist for lruhash markdel callback values.
|
||||
*
|
||||
* @param fptr: function pointer to check.
|
||||
* @return false if not in whitelist.
|
||||
*/
|
||||
int fptr_whitelist_hash_markdelfunc(lruhash_markdelfunc_t fptr);
|
||||
|
||||
/**
|
||||
* Check function pointer whitelist for module_env send_packet callback values.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ bin_delete(struct lruhash* table, struct lruhash_bin* bin)
|
|||
while(p) {
|
||||
np = p->overflow_next;
|
||||
d = p->data;
|
||||
(*table->delkeyfunc)(p->key, table->cb_arg, 0);
|
||||
(*table->delkeyfunc)(p->key, table->cb_arg);
|
||||
(*table->deldatafunc)(d, table->cb_arg);
|
||||
p = np;
|
||||
}
|
||||
|
|
@ -206,7 +206,6 @@ reclaim_space(struct lruhash* table, struct lruhash_entry** list)
|
|||
lock_rw_wrlock(&d->lock);
|
||||
table->space_used -= table->sizefunc(d->key, d->data);
|
||||
if(table->markdelfunc)
|
||||
/* TODO fptr_wlist it */
|
||||
(*table->markdelfunc)(d->key);
|
||||
lock_rw_unlock(&d->lock);
|
||||
lock_quick_unlock(&bin->lock);
|
||||
|
|
@ -307,6 +306,7 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash,
|
|||
log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
|
||||
log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
|
||||
log_assert(fptr_whitelist_hash_compfunc(table->compfunc));
|
||||
log_assert(fptr_whitelist_hash_markdelfunc(table->markdelfunc));
|
||||
need_size = table->sizefunc(entry->key, data);
|
||||
if(cb_arg == NULL) cb_arg = table->cb_arg;
|
||||
|
||||
|
|
@ -327,7 +327,7 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash,
|
|||
/* if so: update data - needs a writelock */
|
||||
table->space_used += need_size -
|
||||
(*table->sizefunc)(found->key, found->data);
|
||||
(*table->delkeyfunc)(entry->key, cb_arg, 0);
|
||||
(*table->delkeyfunc)(entry->key, cb_arg);
|
||||
lru_touch(table, found);
|
||||
lock_rw_wrlock(&found->lock);
|
||||
(*table->deldatafunc)(found->data, cb_arg);
|
||||
|
|
@ -345,7 +345,7 @@ lruhash_insert(struct lruhash* table, hashvalue_t hash,
|
|||
while(reclaimlist) {
|
||||
struct lruhash_entry* n = reclaimlist->overflow_next;
|
||||
void* d = reclaimlist->data;
|
||||
(*table->delkeyfunc)(reclaimlist->key, cb_arg, 0);
|
||||
(*table->delkeyfunc)(reclaimlist->key, cb_arg);
|
||||
(*table->deldatafunc)(d, cb_arg);
|
||||
reclaimlist = n;
|
||||
}
|
||||
|
|
@ -383,6 +383,7 @@ lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key)
|
|||
log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
|
||||
log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
|
||||
log_assert(fptr_whitelist_hash_compfunc(table->compfunc));
|
||||
log_assert(fptr_whitelist_hash_markdelfunc(table->markdelfunc));
|
||||
|
||||
lock_quick_lock(&table->lock);
|
||||
bin = &table->array[hash & table->size_mask];
|
||||
|
|
@ -400,13 +401,12 @@ lruhash_remove(struct lruhash* table, hashvalue_t hash, void* key)
|
|||
lock_quick_unlock(&table->lock);
|
||||
lock_rw_wrlock(&entry->lock);
|
||||
if(table->markdelfunc)
|
||||
/* TODO fptr wlist it */
|
||||
(*table->markdelfunc)(entry->key);
|
||||
lock_rw_unlock(&entry->lock);
|
||||
lock_quick_unlock(&bin->lock);
|
||||
/* finish removal */
|
||||
d = entry->data;
|
||||
(*table->delkeyfunc)(entry->key, table->cb_arg, 0);
|
||||
(*table->delkeyfunc)(entry->key, table->cb_arg);
|
||||
(*table->deldatafunc)(d, table->cb_arg);
|
||||
}
|
||||
|
||||
|
|
@ -423,10 +423,9 @@ bin_clear(struct lruhash* table, struct lruhash_bin* bin)
|
|||
np = p->overflow_next;
|
||||
d = p->data;
|
||||
if(table->markdelfunc)
|
||||
/* TODO fptr wlist it */
|
||||
(*table->markdelfunc)(p->key);
|
||||
lock_rw_unlock(&p->lock);
|
||||
(*table->delkeyfunc)(p->key, table->cb_arg, 0);
|
||||
(*table->delkeyfunc)(p->key, table->cb_arg);
|
||||
(*table->deldatafunc)(d, table->cb_arg);
|
||||
p = np;
|
||||
}
|
||||
|
|
@ -442,6 +441,7 @@ lruhash_clear(struct lruhash* table)
|
|||
return;
|
||||
log_assert(fptr_whitelist_hash_delkeyfunc(table->delkeyfunc));
|
||||
log_assert(fptr_whitelist_hash_deldatafunc(table->deldatafunc));
|
||||
log_assert(fptr_whitelist_hash_markdelfunc(table->markdelfunc));
|
||||
|
||||
lock_quick_lock(&table->lock);
|
||||
for(i=0; i<table->size; i++) {
|
||||
|
|
|
|||
|
|
@ -130,13 +130,9 @@ typedef size_t (*lruhash_sizefunc_t)(void*, void*);
|
|||
typedef int (*lruhash_compfunc_t)(void*, void*);
|
||||
|
||||
/** old keys are deleted.
|
||||
* If is_locked is set, then the routine must unlock the item before deletion.
|
||||
* If is_locked is not set, then this item is not locked. This allows the
|
||||
* routine to perform operations within the critical region of the lock
|
||||
* of the key. The critical region has been locked before the delete happened.
|
||||
* The RRset type has to revoke its ID number inside the critical region.
|
||||
* This function is called: func(key, userarg, is_locked) */
|
||||
typedef void (*lruhash_delkeyfunc_t)(void*, void*, int);
|
||||
* The RRset type has to revoke its ID number, markdel() is used first.
|
||||
* This function is called: func(key, userarg) */
|
||||
typedef void (*lruhash_delkeyfunc_t)(void*, void*);
|
||||
|
||||
/** old data is deleted. This function is called: func(data, userarg). */
|
||||
typedef void (*lruhash_deldatafunc_t)(void*, void*);
|
||||
|
|
|
|||
|
|
@ -192,9 +192,8 @@ int test_slabhash_compfunc(void* key1, void* key2)
|
|||
return -1;
|
||||
}
|
||||
|
||||
void test_slabhash_delkey(void* key, void* ATTR_UNUSED(arg), int l)
|
||||
void test_slabhash_delkey(void* key, void* ATTR_UNUSED(arg))
|
||||
{
|
||||
if(l) { lock_rw_unlock(&((struct slabhash_testkey*)key)->entry.lock); }
|
||||
delkey((struct slabhash_testkey*)key);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ size_t test_slabhash_sizefunc(void*, void*);
|
|||
/** test comparefunc for lruhash */
|
||||
int test_slabhash_compfunc(void*, void*);
|
||||
/** test delkey for lruhash */
|
||||
void test_slabhash_delkey(void*, void*, int);
|
||||
void test_slabhash_delkey(void*, void*);
|
||||
/** test deldata for lruhash */
|
||||
void test_slabhash_deldata(void*, void*);
|
||||
/* --- end test representation --- */
|
||||
|
|
|
|||
|
|
@ -72,14 +72,11 @@ key_entry_compfunc(void* k1, void* k2)
|
|||
}
|
||||
|
||||
void
|
||||
key_entry_delkeyfunc(void* key, void* ATTR_UNUSED(userarg), int islocked)
|
||||
key_entry_delkeyfunc(void* key, void* ATTR_UNUSED(userarg))
|
||||
{
|
||||
struct key_entry_key* kk = (struct key_entry_key*)key;
|
||||
if(!key)
|
||||
return;
|
||||
if(islocked) {
|
||||
lock_rw_unlock(&kk->entry.lock);
|
||||
}
|
||||
free(kk->name);
|
||||
free(kk);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ size_t key_entry_sizefunc(void* key, void* data);
|
|||
int key_entry_compfunc(void* k1, void* k2);
|
||||
|
||||
/** function for lruhash operation */
|
||||
void key_entry_delkeyfunc(void* key, void* userarg, int islocked);
|
||||
void key_entry_delkeyfunc(void* key, void* userarg);
|
||||
|
||||
/** function for lruhash operation */
|
||||
void key_entry_deldatafunc(void* data, void* userarg);
|
||||
|
|
|
|||
Loading…
Reference in a new issue