]> err.no Git - varnish/commitdiff
Introduce LOCK() and UNLOCK() macros which does the right thing
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 24 Aug 2006 07:17:35 +0000 (07:17 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 24 Aug 2006 07:17:35 +0000 (07:17 +0000)
with pthread_mutex_{lock,unlock}()

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@913 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_backend.c
varnish-cache/bin/varnishd/cache_expire.c
varnish-cache/bin/varnishd/cache_hash.c
varnish-cache/bin/varnishd/cache_pool.c
varnish-cache/bin/varnishd/cache_session.c
varnish-cache/bin/varnishd/cache_vcl.c
varnish-cache/bin/varnishd/hash_classic.c
varnish-cache/bin/varnishd/hash_simple_list.c
varnish-cache/bin/varnishd/shmlog.c
varnish-cache/bin/varnishd/storage_file.c
varnish-cache/include/libvarnish.h

index 9c8ac6a4a904493923d293fac9f7b5e73a35057d..950be40663f40bfa308732469d04a6bde5cbc39e 100644 (file)
@@ -187,7 +187,7 @@ VBE_GetFd(struct backend *bp, unsigned xid)
                 * (if any) while we have the lock anyway.
                 */
                vc2 = NULL;
-               AZ(pthread_mutex_lock(&vbemtx));
+               LOCK(&vbemtx);
                vc = TAILQ_FIRST(&bp->connlist);
                if (vc != NULL) {
                        assert(vc->fd >= 0);
@@ -199,7 +199,7 @@ VBE_GetFd(struct backend *bp, unsigned xid)
                                TAILQ_REMOVE(&vbe_head, vc2, list);
                        }
                }
-               AZ(pthread_mutex_unlock(&vbemtx));
+               UNLOCK(&vbemtx);
                if (vc == NULL)
                        break;
 
@@ -226,7 +226,7 @@ VBE_GetFd(struct backend *bp, unsigned xid)
        if (vc->fd < 0) {
                assert(vc->backend == NULL);
                vc->fd = vbe_connect(bp);
-               AZ(pthread_mutex_lock(&vbemtx));
+               LOCK(&vbemtx);
                if (vc->fd < 0) {
                        vc->backend = NULL;
                        TAILQ_INSERT_HEAD(&vbe_head, vc, list);
@@ -235,7 +235,7 @@ VBE_GetFd(struct backend *bp, unsigned xid)
                } else {
                        vc->backend = bp;
                }
-               AZ(pthread_mutex_unlock(&vbemtx));
+               UNLOCK(&vbemtx);
        } else {
                assert(vc->fd >= 0);
                assert(vc->backend == bp);
@@ -263,10 +263,10 @@ VBE_ClosedFd(struct vbe_conn *vc, int already)
                AZ(close(vc->fd));
        vc->fd = -1;
        vc->backend = NULL;
-       AZ(pthread_mutex_lock(&vbemtx));
+       LOCK(&vbemtx);
        TAILQ_INSERT_HEAD(&vbe_head, vc, list);
        VSL_stats->backend_unused++;
-       AZ(pthread_mutex_unlock(&vbemtx));
+       UNLOCK(&vbemtx);
 }
 
 /* Recycle a connection ----------------------------------------------*/
@@ -280,9 +280,9 @@ VBE_RecycleFd(struct vbe_conn *vc)
        assert(vc->backend != NULL);
        VSL_stats->backend_recycle++;
        VSL(SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name);
-       AZ(pthread_mutex_lock(&vbemtx));
+       LOCK(&vbemtx);
        TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list);
-       AZ(pthread_mutex_unlock(&vbemtx));
+       UNLOCK(&vbemtx);
 }
 
 /*--------------------------------------------------------------------*/
index 4e416362b1a6073178422e3971232e1530960b50..f65a68e0958459058dc2edb7e81d7f8810aadfe9 100644 (file)
@@ -32,19 +32,19 @@ EXP_Insert(struct object *o)
 {
 
        assert(o->heap_idx == 0);
-       AZ(pthread_mutex_lock(&exp_mtx));
+       LOCK(&exp_mtx);
        binheap_insert(exp_heap, o);
-       AZ(pthread_mutex_unlock(&exp_mtx));
+       UNLOCK(&exp_mtx);
 }
 
 void
 EXP_TTLchange(struct object *o)
 {
        assert(o->heap_idx != 0);
-       AZ(pthread_mutex_lock(&exp_mtx));
+       LOCK(&exp_mtx);
        binheap_delete(exp_heap, o->heap_idx);
        binheap_insert(exp_heap, o);
-       AZ(pthread_mutex_unlock(&exp_mtx));
+       UNLOCK(&exp_mtx);
 }
 
 /*--------------------------------------------------------------------
@@ -61,7 +61,7 @@ exp_hangman(void *arg)
 
        while (1) {
                t = time(NULL); 
-               AZ(pthread_mutex_lock(&exp_mtx));
+               LOCK(&exp_mtx);
                TAILQ_FOREACH(o, &exp_deathrow, deathrow) {
                        CHECK_OBJ(o, OBJECT_MAGIC);
                        if (o->ttl >= t) {
@@ -77,14 +77,14 @@ exp_hangman(void *arg)
                                break;
                }
                if (o == NULL) {
-                       AZ(pthread_mutex_unlock(&exp_mtx));
+                       UNLOCK(&exp_mtx);
                        AZ(sleep(1));
                        continue;
                }
                TAILQ_REMOVE(&exp_deathrow, o, deathrow);
                VSL_stats->n_deathrow--;
                VSL_stats->n_expired++;
-               AZ(pthread_mutex_unlock(&exp_mtx));
+               UNLOCK(&exp_mtx);
                VSL(SLT_ExpKill, 0, "%u %d", o->xid, (int)(o->ttl - t));
                HSH_Deref(o);
        }
@@ -113,12 +113,12 @@ exp_prefetch(void *arg)
        assert(sp != NULL);
        while (1) {
                t = time(NULL);
-               AZ(pthread_mutex_lock(&exp_mtx));
+               LOCK(&exp_mtx);
                o = binheap_root(exp_heap);
                if (o != NULL)
                        CHECK_OBJ(o, OBJECT_MAGIC);
                if (o == NULL || o->ttl > t + expearly) {
-                       AZ(pthread_mutex_unlock(&exp_mtx));
+                       UNLOCK(&exp_mtx);
                        AZ(sleep(1));
                        continue;
                }
@@ -129,7 +129,7 @@ exp_prefetch(void *arg)
                if (o2 != NULL)
                        assert(o2->ttl >= o->ttl);
 
-               AZ(pthread_mutex_unlock(&exp_mtx));
+               UNLOCK(&exp_mtx);
                VSL(SLT_ExpPick, 0, "%u", o->xid);
 
                sp->vcl = VCL_Get();
@@ -138,10 +138,10 @@ exp_prefetch(void *arg)
                VCL_Rel(sp->vcl);
 
                if (sp->handling == VCL_RET_DISCARD) {
-                       AZ(pthread_mutex_lock(&exp_mtx));
+                       LOCK(&exp_mtx);
                        TAILQ_INSERT_TAIL(&exp_deathrow, o, deathrow);
                        VSL_stats->n_deathrow++;
-                       AZ(pthread_mutex_unlock(&exp_mtx));
+                       UNLOCK(&exp_mtx);
                        continue;
                }
                assert(sp->handling == VCL_RET_DISCARD);
index 1822ef34f632a98babdeccd676231ed45d222329..0a5ac84e037670b420e6e1439be80b8e0bd198e3 100644 (file)
@@ -85,20 +85,20 @@ HSH_Lookup(struct sess *sp)
                o = sp->obj;
                oh = o->objhead;
                CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
-               AZ(pthread_mutex_lock(&oh->mtx));
+               LOCK(&oh->mtx);
                goto were_back;
        }
        oh = hash->lookup(url, host, w->nobjhead);
        CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
        if (oh == w->nobjhead)
                w->nobjhead = NULL;
-       AZ(pthread_mutex_lock(&oh->mtx));
+       LOCK(&oh->mtx);
        TAILQ_FOREACH(o, &oh->objects, list) {
                o->refcnt++;
                if (o->busy) {
                        TAILQ_INSERT_TAIL(&o->waitinglist, sp, list);
                        sp->obj = o;
-                       AZ(pthread_mutex_unlock(&oh->mtx));
+                       UNLOCK(&oh->mtx);
                        return (NULL);
                }
        were_back:
@@ -118,7 +118,7 @@ HSH_Lookup(struct sess *sp)
                o->refcnt--;
        }
        if (o != NULL) {
-               AZ(pthread_mutex_unlock(&oh->mtx));
+               UNLOCK(&oh->mtx);
                (void)hash->deref(oh);
                return (o);
        }
@@ -129,7 +129,7 @@ HSH_Lookup(struct sess *sp)
        o->objhead = oh;
        TAILQ_INSERT_TAIL(&oh->objects, o, list);
        /* NB: do not deref objhead the new object inherits our reference */
-       AZ(pthread_mutex_unlock(&oh->mtx));
+       UNLOCK(&oh->mtx);
        BAN_NewObj(o);
        return (o);
 }
@@ -144,9 +144,9 @@ HSH_Unbusy(struct object *o)
        assert(o->refcnt > 0);
        if (o->cacheable)
                EXP_Insert(o);
-       AZ(pthread_mutex_lock(&o->objhead->mtx));
+       LOCK(&o->objhead->mtx);
        o->busy = 0;
-       AZ(pthread_mutex_unlock(&o->objhead->mtx));
+       UNLOCK(&o->objhead->mtx);
        while (1) {
                sp = TAILQ_FIRST(&o->waitinglist);
                if (sp == NULL)
@@ -164,10 +164,10 @@ HSH_Ref(struct object *o)
        CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
        oh = o->objhead;
        CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
-       AZ(pthread_mutex_lock(&oh->mtx));
+       LOCK(&oh->mtx);
        assert(o->refcnt > 0);
        o->refcnt++;
-       AZ(pthread_mutex_unlock(&oh->mtx));
+       UNLOCK(&oh->mtx);
 }
 
 void
@@ -182,12 +182,12 @@ HSH_Deref(struct object *o)
        CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC);
 
        /* drop ref on object */
-       AZ(pthread_mutex_lock(&oh->mtx));
+       LOCK(&oh->mtx);
        assert(o->refcnt > 0);
        r = --o->refcnt;
        if (!r)
                TAILQ_REMOVE(&oh->objects, o, list);
-       AZ(pthread_mutex_unlock(&oh->mtx));
+       UNLOCK(&oh->mtx);
 
        /* If still referenced, done */
        if (r != 0)
index 862b0c6f2b3795d27de43b137a73cac9f53e8b41..234422804b28a1b91ae00e3ed8627b58a7437b1f 100644 (file)
@@ -132,7 +132,7 @@ wrk_do_one(struct worker *w)
        VSL_stats->n_wrk_busy++;
        TAILQ_REMOVE(&wrk_reqhead, wrq, list);
        VSL_stats->n_wrk_queue--;
-       AZ(pthread_mutex_unlock(&wrk_mtx));
+       UNLOCK(&wrk_mtx);
        CHECK_OBJ_NOTNULL(wrq->sess, SESS_MAGIC);
        wrq->sess->wrk = w;
        w->wrq = wrq;
@@ -150,7 +150,7 @@ wrk_do_one(struct worker *w)
        if (w->nobjhead != NULL)
                CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC);
        w->wrq = NULL;
-       AZ(pthread_mutex_lock(&wrk_mtx));
+       LOCK(&wrk_mtx);
        VSL_stats->n_wrk_busy--;
 }
 
@@ -167,7 +167,7 @@ wrk_thread(void *priv)
 
        AZ(pthread_cond_init(&w->cv, NULL));
 
-       AZ(pthread_mutex_lock(&wrk_mtx));
+       LOCK(&wrk_mtx);
        w->nbr = VSL_stats->n_wrk;
        VSL_stats->n_wrk_create++;
        VSL(SLT_WorkThread, 0, "%u born", w->nbr);
@@ -195,7 +195,7 @@ wrk_thread(void *priv)
                        if (pthread_cond_timedwait(&w->cv, &wrk_mtx, &ts)) {
                                VSL_stats->n_wrk--;
                                TAILQ_REMOVE(&wrk_idle, w, list);
-                               AZ(pthread_mutex_unlock(&wrk_mtx));
+                               UNLOCK(&wrk_mtx);
                                VSL(SLT_WorkThread, 0, "%u suicide", w->nbr);
                                AZ(pthread_cond_destroy(&w->cv));
                                return (NULL);
@@ -219,7 +219,7 @@ WRK_QueueSession(struct sess *sp)
 
        sp->workreq.sess = sp;
 
-       AZ(pthread_mutex_lock(&wrk_mtx));
+       LOCK(&wrk_mtx);
        TAILQ_INSERT_TAIL(&wrk_reqhead, &sp->workreq, list);
        VSL_stats->n_wrk_queue++;
 
@@ -229,7 +229,7 @@ WRK_QueueSession(struct sess *sp)
                AZ(pthread_cond_signal(&w->cv));
                TAILQ_REMOVE(&wrk_idle, w, list);
                TAILQ_INSERT_TAIL(&wrk_busy, w, list);
-               AZ(pthread_mutex_unlock(&wrk_mtx));
+               UNLOCK(&wrk_mtx);
                return;
        }
        
@@ -238,13 +238,13 @@ WRK_QueueSession(struct sess *sp)
        /* Can we create more threads ? */
        if (VSL_stats->n_wrk >= params->wthread_max) {
                VSL_stats->n_wrk_max++;
-               AZ(pthread_mutex_unlock(&wrk_mtx));
+               UNLOCK(&wrk_mtx);
                return;
        }
 
        /* Try to create a thread */
        VSL_stats->n_wrk++;
-       AZ(pthread_mutex_unlock(&wrk_mtx));
+       UNLOCK(&wrk_mtx);
 
        if (!pthread_create(&tp, NULL, wrk_thread, NULL)) {
                AZ(pthread_detach(tp));
@@ -255,10 +255,10 @@ WRK_QueueSession(struct sess *sp)
            errno, strerror(errno));
 
        /* Register overflow */
-       AZ(pthread_mutex_lock(&wrk_mtx));
+       LOCK(&wrk_mtx);
        VSL_stats->n_wrk--;
        VSL_stats->n_wrk_failed++;
-       AZ(pthread_mutex_unlock(&wrk_mtx));
+       UNLOCK(&wrk_mtx);
 }
        
 
@@ -293,7 +293,7 @@ cli_func_dump_pool(struct cli *cli, char **av, void *priv)
        (void)av;
        (void)priv;
        struct worker *w;
-       AZ(pthread_mutex_lock(&wrk_mtx));
+       LOCK(&wrk_mtx);
        t = time(NULL);
        TAILQ_FOREACH(w, &wrk_busy, list) {
                cli_out(cli, "\n");
@@ -313,5 +313,5 @@ cli_func_dump_pool(struct cli *cli, char **av, void *priv)
        TAILQ_FOREACH(w, &wrk_idle, list)
                u++;
        cli_out(cli, "%u idle workers\n", u);
-       AZ(pthread_mutex_unlock(&wrk_mtx));
+       UNLOCK(&wrk_mtx);
 }
index 0cfea52437eed57c5ead7a069f15681281e14e0b..f68a9e976bdefd9d9f2f63438855b670f0310d47 100644 (file)
@@ -79,7 +79,7 @@ SES_RefSrcAddr(struct sess *sp)
        ch = &srcaddr_hash[v];
        now = time(NULL);
 
-       AZ(pthread_mutex_lock(&ses_mtx));
+       LOCK(&ses_mtx);
        c3 = NULL;
        TAILQ_FOREACH_SAFE(c, ch, list, c2) {
                if (c->hash == u && !strcmp(c->addr, sp->addr)) {
@@ -95,7 +95,7 @@ SES_RefSrcAddr(struct sess *sp)
                                VSL_stats->n_srcaddr--;
                                free(c3);
                        }
-                       AZ(pthread_mutex_unlock(&ses_mtx));
+                       UNLOCK(&ses_mtx);
                        return;
                }
                if (c->nref > 0 || c->ttl > now)
@@ -128,7 +128,7 @@ SES_RefSrcAddr(struct sess *sp)
                TAILQ_INSERT_TAIL(ch, c3, list);
                sp->srcaddr = c3;
        }
-       AZ(pthread_mutex_unlock(&ses_mtx));
+       UNLOCK(&ses_mtx);
 }
 
 static void
@@ -152,7 +152,7 @@ SES_Charge(struct sess *sp)
 
        ses_sum_acct(&sp->acct, a);
        
-       AZ(pthread_mutex_lock(&ses_mtx));
+       LOCK(&ses_mtx);
        ses_sum_acct(b, a);
        VSL(SLT_StatAddr, 0, "%s 0 %d %ju %ju %ju %ju %ju %ju %ju",
            sp->srcaddr->addr, time(NULL) - b->first,
@@ -165,7 +165,7 @@ SES_Charge(struct sess *sp)
        VSL_stats->s_fetch += a->fetch;
        VSL_stats->s_hdrbytes += a->hdrbytes;
        VSL_stats->s_bodybytes += a->bodybytes;
-       AZ(pthread_mutex_unlock(&ses_mtx));
+       UNLOCK(&ses_mtx);
        memset(a, 0, sizeof *a);
 }
 
@@ -178,13 +178,13 @@ ses_relsrcaddr(struct sess *sp)
                return;
        }
        assert(sp->srcaddr != NULL);
-       AZ(pthread_mutex_lock(&ses_mtx));
+       LOCK(&ses_mtx);
        assert(sp->srcaddr->nref > 0);
        sp->srcaddr->nref--;
        if (sp->srcaddr->nref == 0)
                VSL_stats->n_srcaddr_act--;
        sp->srcaddr = NULL;
-       AZ(pthread_mutex_unlock(&ses_mtx));
+       UNLOCK(&ses_mtx);
 }
 
 /*--------------------------------------------------------------------*/
@@ -207,9 +207,9 @@ SES_New(struct sockaddr *addr, unsigned len)
                 * If that queue is empty, flip queues holding the lock
                 * and try the new unlocked queue.
                 */
-               AZ(pthread_mutex_lock(&ses_mem_mtx));
+               LOCK(&ses_mem_mtx);
                ses_qp = 1 - ses_qp;
-               AZ(pthread_mutex_unlock(&ses_mem_mtx));
+               UNLOCK(&ses_mem_mtx);
                sm = TAILQ_FIRST(&ses_free_mem[ses_qp]);
        }
        if (sm != NULL) {
@@ -271,9 +271,9 @@ SES_Delete(struct sess *sp)
                VSL_stats->n_sess_mem--;
                free(sm);
        } else {
-               AZ(pthread_mutex_lock(&ses_mem_mtx));
+               LOCK(&ses_mem_mtx);
                TAILQ_INSERT_HEAD(&ses_free_mem[1 - ses_qp], sm, list);
-               AZ(pthread_mutex_unlock(&ses_mem_mtx));
+               UNLOCK(&ses_mem_mtx);
        }
 }
 
index 10b6d4e1551ad9fa95e0d824087af368de78ec44..f9c11db6eaa33b8e767eae30554a5819ecf8379e 100644 (file)
@@ -46,12 +46,12 @@ VCL_Get(void)
 {
        struct VCL_conf *vc;
 
-       AZ(pthread_mutex_lock(&vcl_mtx));
+       LOCK(&vcl_mtx);
        assert(vcl_active != NULL);
        vc = vcl_active->conf;
        assert(vc != NULL);
        vc->busy++;
-       AZ(pthread_mutex_unlock(&vcl_mtx));
+       UNLOCK(&vcl_mtx);
        return (vc);
 }
 
@@ -60,7 +60,7 @@ VCL_Rel(struct VCL_conf *vc)
 {
        struct vcls *vcl;
 
-       AZ(pthread_mutex_lock(&vcl_mtx));
+       LOCK(&vcl_mtx);
        assert(vc->busy > 0);
        vc->busy--;
        vcl = vc->priv; /* XXX miniobj */
@@ -72,7 +72,7 @@ VCL_Rel(struct VCL_conf *vc)
        } else {
                vcl = NULL;
        }
-       AZ(pthread_mutex_unlock(&vcl_mtx));
+       UNLOCK(&vcl_mtx);
        if (vcl != NULL) {
                /* XXX: dispose of vcl */
        }
@@ -142,10 +142,10 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
        vcl->name = strdup(name);
        assert(vcl->name != NULL);
        TAILQ_INSERT_TAIL(&vcl_head, vcl, list);
-       AZ(pthread_mutex_lock(&vcl_mtx));
+       LOCK(&vcl_mtx);
        if (vcl_active == NULL)
                vcl_active = vcl;
-       AZ(pthread_mutex_unlock(&vcl_mtx));
+       UNLOCK(&vcl_mtx);
        if (cli == NULL)
                fprintf(stderr, "Loaded \"%s\" as \"%s\"\n", fn , name);
        else 
@@ -200,9 +200,9 @@ cli_func_config_discard(struct cli *cli, char **av, void *priv)
                cli_out(cli, "VCL %s already discarded", av[2]);
                return;
        }
-       AZ(pthread_mutex_lock(&vcl_mtx));
+       LOCK(&vcl_mtx);
        if (vcl == vcl_active) {
-               AZ(pthread_mutex_unlock(&vcl_mtx));
+               UNLOCK(&vcl_mtx);
                cli_result(cli, CLIS_PARAM);
                cli_out(cli, "VCL %s is the active VCL", av[2]);
                return;
@@ -212,7 +212,7 @@ cli_func_config_discard(struct cli *cli, char **av, void *priv)
                TAILQ_REMOVE(&vcl_head, vcl, list);
        else
                vcl = NULL;
-       AZ(pthread_mutex_unlock(&vcl_mtx));
+       UNLOCK(&vcl_mtx);
        if (vcl != NULL) {
                /* XXX dispose of vcl */
        }
@@ -236,9 +236,9 @@ cli_func_config_use(struct cli *cli, char **av, void *priv)
                cli_result(cli, CLIS_PARAM);
                return;
        }
-       AZ(pthread_mutex_lock(&vcl_mtx));
+       LOCK(&vcl_mtx);
        vcl_active = vcl;
-       AZ(pthread_mutex_unlock(&vcl_mtx));
+       UNLOCK(&vcl_mtx);
 }
 
 /*--------------------------------------------------------------------*/
index 9cba4e348d1865f42669e303642eba3bdc66ae74..f0eca583a98ca28ac2c67cd50ebe79013c1d20e0 100644 (file)
@@ -180,7 +180,7 @@ hcl_lookup(const char *key1, const char *key2, struct objhead *noh)
        he2 = NULL;
 
        for (r = 0; r < 2; r++ ) {
-               AZ(pthread_mutex_lock(&hp->mtx));
+               LOCK(&hp->mtx);
                TAILQ_FOREACH(he, &hp->head, list) {
                        CHECK_OBJ_NOTNULL(he, HCL_ENTRY_MAGIC);
                        if (kl < he->klen)
@@ -197,13 +197,13 @@ hcl_lookup(const char *key1, const char *key2, struct objhead *noh)
                                continue;
                        he->refcnt++;
                        noh = he->oh;
-                       AZ(pthread_mutex_unlock(&hp->mtx));
+                       UNLOCK(&hp->mtx);
                        if (he2 != NULL)
                                free(he2);
                        return (noh);
                }
                if (noh == NULL) {
-                       AZ(pthread_mutex_unlock(&hp->mtx));
+                       UNLOCK(&hp->mtx);
                        return (NULL);
                }
                if (he2 != NULL) {
@@ -213,10 +213,10 @@ hcl_lookup(const char *key1, const char *key2, struct objhead *noh)
                                TAILQ_INSERT_TAIL(&hp->head, he2, list);
                        he2->refcnt++;
                        noh = he2->oh;
-                       AZ(pthread_mutex_unlock(&hp->mtx));
+                       UNLOCK(&hp->mtx);
                        return (noh);
                }
-               AZ(pthread_mutex_unlock(&hp->mtx));
+               UNLOCK(&hp->mtx);
 
                i = sizeof *he2 + kl;
                he2 = calloc(i, 1);
@@ -254,12 +254,12 @@ hcl_deref(struct objhead *oh)
        assert(he->refcnt > 0);
        assert(he->hash < hcl_nhash);
        assert(hp == &hcl_head[he->hash]);
-       AZ(pthread_mutex_lock(&hp->mtx));
+       LOCK(&hp->mtx);
        if (--he->refcnt == 0)
                TAILQ_REMOVE(&hp->head, he, list);
        else
                he = NULL;
-       AZ(pthread_mutex_unlock(&hp->mtx));
+       UNLOCK(&hp->mtx);
        if (he == NULL)
                return (1);
        free(he);
index ce2626730edc68dad0223ca21ce0ad2c954b30a1..69f3a241f4b88fd23bc8aad6e7b10a54c73f769e 100644 (file)
@@ -48,7 +48,7 @@ hsl_lookup(const char *key1, const char *key2, struct objhead *nobj)
        struct hsl_entry *he, *he2;
        int i;
 
-       AZ(pthread_mutex_lock(&hsl_mutex));
+       LOCK(&hsl_mutex);
        TAILQ_FOREACH(he, &hsl_head, list) {
                i = strcmp(key1, he->key1);
                if (i < 0)
@@ -63,11 +63,11 @@ hsl_lookup(const char *key1, const char *key2, struct objhead *nobj)
                he->refcnt++;
                nobj = he->obj;
                nobj->hashpriv = he;
-               AZ(pthread_mutex_unlock(&hsl_mutex));
+               UNLOCK(&hsl_mutex);
                return (nobj);
        }
        if (nobj == NULL) {
-               AZ(pthread_mutex_unlock(&hsl_mutex));
+               UNLOCK(&hsl_mutex);
                return (NULL);
        }
        he2 = calloc(sizeof *he2, 1);
@@ -83,7 +83,7 @@ hsl_lookup(const char *key1, const char *key2, struct objhead *nobj)
                TAILQ_INSERT_BEFORE(he, he2, list);
        else
                TAILQ_INSERT_TAIL(&hsl_head, he2, list);
-       AZ(pthread_mutex_unlock(&hsl_mutex));
+       UNLOCK(&hsl_mutex);
        return (nobj);
 }
 
@@ -99,7 +99,7 @@ hsl_deref(struct objhead *obj)
 
        assert(obj->hashpriv != NULL);
        he = obj->hashpriv;
-       AZ(pthread_mutex_lock(&hsl_mutex));
+       LOCK(&hsl_mutex);
        if (--he->refcnt == 0) {
                free(he->key1);
                free(he->key2);
@@ -108,7 +108,7 @@ hsl_deref(struct objhead *obj)
                ret = 0;
        } else
                ret = 1;
-       AZ(pthread_mutex_unlock(&hsl_mutex));
+       UNLOCK(&hsl_mutex);
        return (ret);
 }
 
index 7db7d48f8c08018cad271ecc894fc6198981b62c..be69874c79ee3cccb30dc9b97cb6a5f94c9edeba 100644 (file)
@@ -62,7 +62,7 @@ VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e)
        }
 
        /* Only hold the lock while we find our space */
-       AZ(pthread_mutex_lock(&vsl_mtx));
+       LOCK(&vsl_mtx);
        assert(loghead->ptr < loghead->size);
 
        /* Wrap if necessary */
@@ -72,7 +72,7 @@ VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e)
        loghead->ptr += 5 + l;
        p[5 + l] = SLT_ENDMARKER;
        assert(loghead->ptr < loghead->size);
-       AZ(pthread_mutex_unlock(&vsl_mtx));
+       UNLOCK(&vsl_mtx);
 
        p[1] = l & 0xff;
        p[2] = (id >> 8) & 0xff;
@@ -99,7 +99,7 @@ VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...)
                return;
        }
 
-       AZ(pthread_mutex_lock(&vsl_mtx));
+       LOCK(&vsl_mtx);
        assert(loghead->ptr < loghead->size);
 
        /* Wrap if we cannot fit a full size record */
@@ -123,7 +123,7 @@ VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...)
        loghead->ptr += 5 + n;
        assert(loghead->ptr < loghead->size);
        
-       AZ(pthread_mutex_unlock(&vsl_mtx));
+       UNLOCK(&vsl_mtx);
 
        va_end(ap);
 }
index a0521fe705b5d725aaabe7d815f9d24989b79fae..0db5ced8af7cb883d7f57ea94f18f1e647f43380 100644 (file)
@@ -511,10 +511,10 @@ smf_alloc(struct stevedore *st, size_t size)
 
        size += (sc->pagesize - 1);
        size &= ~(sc->pagesize - 1);
-       AZ(pthread_mutex_lock(&sc->mtx));
+       LOCK(&sc->mtx);
        smf = alloc_smf(sc, size);
        CHECK_OBJ_NOTNULL(smf, SMF_MAGIC);
-       AZ(pthread_mutex_unlock(&sc->mtx));
+       UNLOCK(&sc->mtx);
        assert(smf != NULL);
        assert(smf->size == size);
        smf->s.space = size;
@@ -549,10 +549,10 @@ smf_trim(struct storage *s, size_t size)
        size += (sc->pagesize - 1);
        size &= ~(sc->pagesize - 1);
        if (smf->size > size) {
-               AZ(pthread_mutex_lock(&sc->mtx));
+               LOCK(&sc->mtx);
                trim_smf(smf, size);
                assert(smf->size == size);
-               AZ(pthread_mutex_unlock(&sc->mtx));
+               UNLOCK(&sc->mtx);
                smf->s.space = size;
        }
 }
@@ -568,9 +568,9 @@ smf_free(struct storage *s)
        CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC);
        CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC);
        sc = smf->sc;
-       AZ(pthread_mutex_lock(&sc->mtx));
+       LOCK(&sc->mtx);
        free_smf(smf);
-       AZ(pthread_mutex_unlock(&sc->mtx));
+       UNLOCK(&sc->mtx);
 }
 
 /*--------------------------------------------------------------------*/
index 1580fed4a2d31f167c994e552ee09010cc07d414..10a9675ad9dfd1c750a3ac0093292fb018862d56 100644 (file)
@@ -51,3 +51,6 @@ void lbv_xxxassert(const char *, const char *, int, const char *, int);
 #define AN(foo)        do { assert((foo) != NULL); } while (0)
 #define XXXAZ(foo)     do { xxxassert((foo) == 0); } while (0)
 #define XXXAN(foo)     do { xxxassert((foo) != NULL); } while (0)
+
+#define LOCK(foo)      AZ(pthread_mutex_lock(foo))
+#define UNLOCK(foo)    AZ(pthread_mutex_unlock(foo))