From a2311972e7c03d709188d27106e0389d96315a21 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 5 Dec 2007 06:41:39 +0000 Subject: [PATCH] locking diff. git-svn-id: file:///svn/unbound/trunk@807 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 3 +++ libunbound/context.c | 5 +++++ libunbound/unbound.c | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 60c85a699..63397cef4 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +5 December 2007: Wouter + - locking in context_new() inside the function. + 4 December 2007: Wouter - minor Makefile fixup. - moved module-stack code out of daemon/daemon into services/modstack, diff --git a/libunbound/context.c b/libunbound/context.c index 90a38495f..1f971f2b5 100644 --- a/libunbound/context.c +++ b/libunbound/context.c @@ -116,10 +116,13 @@ context_new(struct ub_val_ctx* ctx, char* name, int rrtype, int rrclass, { struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q)); if(!q) return NULL; + lock_basic_lock(&ctx->cfglock); if(!find_id(ctx, &q->querynum)) { + lock_basic_unlock(&ctx->cfglock); free(q); return NULL; } + lock_basic_unlock(&ctx->cfglock); q->node.key = &q->querynum; q->async = (cb != NULL); q->cb = cb; @@ -139,8 +142,10 @@ context_new(struct ub_val_ctx* ctx, char* name, int rrtype, int rrclass, q->res->qclass = rrclass; /* add to query list */ + lock_basic_lock(&ctx->cfglock); if(q->async) ctx->num_async ++; (void)rbtree_insert(&ctx->queries, &q->node); + lock_basic_unlock(&ctx->cfglock); return q; } diff --git a/libunbound/unbound.c b/libunbound/unbound.c index 198d42c54..e67daeb84 100644 --- a/libunbound/unbound.c +++ b/libunbound/unbound.c @@ -275,8 +275,8 @@ ub_val_resolve(struct ub_val_ctx* ctx, char* name, int rrtype, } } /* create new ctx_query and attempt to add to the list */ - q = context_new(ctx, name, rrtype, rrclass, NULL, NULL); lock_basic_unlock(&ctx->cfglock); + q = context_new(ctx, name, rrtype, rrclass, NULL, NULL); if(!q) return UB_NOMEM; /* become a resolver thread for a bit */ @@ -303,8 +303,8 @@ ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype, } } /* create new ctx_query and attempt to add to the list */ - q = context_new(ctx, name, rrtype, rrclass, callback, mydata); lock_basic_unlock(&ctx->cfglock); + q = context_new(ctx, name, rrtype, rrclass, callback, mydata); if(!q) return UB_NOMEM; /* TODO write over pipe to background worker */ -- 2.47.2