git-svn-id: file:///svn/unbound/trunk@330 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2007-05-22 15:02:39 +00:00
parent 687a99a82e
commit cc48ec587f
9 changed files with 59 additions and 35 deletions

View file

@ -4,6 +4,9 @@
- testbound support for new serviced queries.
- test for retry to TCP cannot use testbound any longer.
- testns test for EDNS fallback, test for TCP fallback already exists.
- fixes for no-locking compile.
- mini_event timer precision and fix for change in timeouts during
timeout callback. Fix for fwd_three tests, performed nonexit query.
21 May 2007: Wouter
- small comment on hash table locking.

View file

@ -75,7 +75,7 @@ infra_host_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
struct infra_host_key* key = (struct infra_host_key*)k;
if(!key)
return;
if(il) lock_rw_unlock(&key->entry.lock);
if(il) { lock_rw_unlock(&key->entry.lock); }
lock_rw_destroy(&key->entry.lock);
free(key);
}
@ -322,7 +322,7 @@ infra_lame_delkeyfunc(void* k, void* ATTR_UNUSED(arg), int il)
struct infra_lame_key* key = (struct infra_lame_key*)k;
if(!key)
return;
if(il) lock_rw_unlock(&key->entry.lock);
if(il) { lock_rw_unlock(&key->entry.lock); }
lock_rw_destroy(&key->entry.lock);
free(key->zonename);
free(key);
@ -397,7 +397,7 @@ infra_set_lame(struct infra_cache* infra,
log_err("set_lame: malloc failure");
if(needtoinsert) slabhash_insert(infra->hosts,
e->hash, e, e->data, NULL);
else lock_rw_unlock(&e->lock);
else { lock_rw_unlock(&e->lock); }
free(k->zonename);
free(k);
free(d);
@ -409,7 +409,7 @@ infra_set_lame(struct infra_cache* infra,
if(needtoinsert)
slabhash_insert(infra->hosts, e->hash, e, e->data, NULL);
else lock_rw_unlock(&e->lock);
else { lock_rw_unlock(&e->lock); }
return 1;
}
@ -436,7 +436,7 @@ infra_rtt_update(struct infra_cache* infra,
if(needtoinsert)
slabhash_insert(infra->hosts, e->hash, e, e->data, NULL);
else lock_rw_unlock(&e->lock);
else { lock_rw_unlock(&e->lock); }
return 1;
}
@ -461,6 +461,6 @@ infra_edns_update(struct infra_cache* infra,
if(needtoinsert)
slabhash_insert(infra->hosts, e->hash, e, e->data, NULL);
else lock_rw_unlock(&e->lock);
else { lock_rw_unlock(&e->lock); }
return 1;
}

View file

@ -526,7 +526,7 @@ static int test_compfunc(void* key1, void* key2)
static void test_delkey(void* key, void* ATTR_UNUSED(arg), int l)
{
if(l) lock_rw_unlock(&((struct testkey*)key)->entry.lock);
if(l) { lock_rw_unlock(&((struct testkey*)key)->entry.lock); }
delkey((struct testkey*)key);
}

View file

@ -406,7 +406,7 @@ static int test_compfunc(void* key1, void* key2)
static void test_delkey(void* key, void* ATTR_UNUSED(arg), int l)
{
if(l) lock_rw_unlock(&((struct slabtestkey*)key)->entry.lock);
if(l) { lock_rw_unlock(&((struct slabtestkey*)key)->entry.lock); }
delkey((struct slabtestkey*)key);
}

Binary file not shown.

Binary file not shown.

View file

@ -499,8 +499,9 @@ void
query_entry_delete(void *k, void* ATTR_UNUSED(arg), int is_locked)
{
struct msgreply_entry* q = (struct msgreply_entry*)k;
if(is_locked)
if(is_locked) {
lock_rw_unlock(&q->entry.lock);
}
lock_rw_destroy(&q->entry.lock);
query_info_clear(&q->key);
free(q);

View file

@ -106,8 +106,9 @@ ub_rrset_key_delete(void* key, void* userdata, int is_locked)
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)
if(is_locked) {
lock_rw_unlock(&k->entry.lock);
}
free(k->rk.dname);
k->rk.dname = NULL;
alloc_special_release(a, k);

View file

@ -115,46 +115,56 @@ const char *event_get_method(void)
}
/** call timeouts handlers, and return how long to wait for next one or -1 */
static void handle_timeouts(struct event_base* base, time_t now, time_t *wait)
static void handle_timeouts(struct event_base* base, struct timeval* now,
struct timeval* wait)
{
struct event* p, *np;
*wait = (time_t)-1;
struct event* p;
#ifndef S_SPLINT_S
wait->tv_sec = (time_t)-1;
#endif
p = (struct event*)rbtree_first(base->times);
while((rbnode_t*)p!=RBTREE_NULL) {
/* store next to make deletion possible */
np = (struct event*)rbtree_next((rbnode_t*)p);
if(!p || p->ev_timeout.tv_sec > now ||
(p->ev_timeout.tv_sec==now && p->ev_timeout.tv_usec>0)) {
while((rbnode_t*)(p = (struct event*)rbtree_first(base->times))
!=RBTREE_NULL) {
#ifndef S_SPLINT_S
if(p->ev_timeout.tv_sec > now->tv_sec ||
(p->ev_timeout.tv_sec==now->tv_sec &&
p->ev_timeout.tv_usec > now->tv_usec)) {
/* there is a next larger timeout. wait for it */
*wait = p->ev_timeout.tv_sec - now;
if(p->ev_timeout.tv_usec > 0)
*wait+=1; /* wait a bit longer */
wait->tv_sec = p->ev_timeout.tv_sec - now->tv_sec;
if(now->tv_usec > p->ev_timeout.tv_usec) {
wait->tv_sec--;
wait->tv_usec = 1000000 - (now->tv_usec -
p->ev_timeout.tv_usec);
} else {
wait->tv_usec = p->ev_timeout.tv_usec
- now->tv_usec;
}
return;
}
#endif
/* event times out, remove it */
(void)rbtree_delete(base->times, p);
p->ev_events &= ~EV_TIMEOUT;
(*p->ev_callback)(p->ev_fd, EV_TIMEOUT, p->ev_arg);
/* next is a valid pointer and next larger element */
p = np;
}
}
/** call select and callbacks for that */
static int handle_select(struct event_base* base, time_t wait)
static int handle_select(struct event_base* base, struct timeval* wait)
{
struct timeval tv;
fd_set r, w;
int ret, i;
tv.tv_sec = wait;
tv.tv_usec = 0;
#ifndef S_SPLINT_S
if(wait->tv_sec==(time_t)-1)
wait = NULL;
#endif
if(wait) log_info("waiting for %d %d", wait->tv_sec, wait->tv_usec);
else log_info("wait forever");
memmove(&r, &base->reads, sizeof(fd_set));
memmove(&w, &base->writes, sizeof(fd_set));
if((ret = select(base->maxfd+1, &r, &w, NULL,
(wait==(time_t)-1)?NULL:&tv)) == -1) {
if((ret = select(base->maxfd+1, &r, &w, NULL, wait)) == -1) {
return -1;
}
@ -185,13 +195,15 @@ static int handle_select(struct event_base* base, time_t wait)
/** run select in a loop */
int event_base_dispatch(struct event_base* base)
{
struct timeval now, wait;
while(!base->need_to_exit)
{
time_t now = time(NULL), wait;
if(gettimeofday(&now, NULL) < 0)
return -1;
/* see if timeouts need handling */
handle_timeouts(base, now, &wait);
handle_timeouts(base, &now, &wait);
/* do select */
if(handle_select(base, wait) < 0) {
if(handle_select(base, &wait) < 0) {
if(base->need_to_exit)
return 0;
return -1;
@ -258,8 +270,15 @@ int event_add(struct event* ev, struct timeval* tv)
}
if(tv && ev->ev_events&EV_TIMEOUT) {
#ifndef S_SPLINT_S
ev->ev_timeout.tv_sec = tv->tv_sec + time(NULL);
ev->ev_timeout.tv_usec = tv->tv_usec;
struct timeval now;
if(gettimeofday(&now, NULL) < 0)
return -1;
ev->ev_timeout.tv_sec = tv->tv_sec + now.tv_sec;
ev->ev_timeout.tv_usec = tv->tv_usec + now.tv_usec;
while(ev->ev_timeout.tv_usec > 1000000) {
ev->ev_timeout.tv_usec -= 1000000;
ev->ev_timeout.tv_sec++;
}
#endif
(void)rbtree_insert(ev->ev_base->times, &ev->node);
}