]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
locking diff.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 5 Dec 2007 06:41:39 +0000 (06:41 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Wed, 5 Dec 2007 06:41:39 +0000 (06:41 +0000)
git-svn-id: file:///svn/unbound/trunk@807 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
libunbound/context.c
libunbound/unbound.c

index 60c85a699f8b7892191776fb652b9cbcf1331cd3..63397cef4199024a92b2cfc20a54c0cb266ff45f 100644 (file)
@@ -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,
index 90a38495ffa1217146894092ff4aa8b0e8695334..1f971f2b51ce1f83cce79372e697b0864272e72f 100644 (file)
@@ -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;
 }
index 198d42c5470a2e7fbe71a34ef5382b2910c54522..e67daeb849f24093cb9a2e9ef19f769f72943d00 100644 (file)
@@ -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 */