From: phk Date: Thu, 24 Aug 2006 07:17:35 +0000 (+0000) Subject: Introduce LOCK() and UNLOCK() macros which does the right thing X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1df57b816990ef27e96922c902debe8c51a058c;p=varnish Introduce LOCK() and UNLOCK() macros which does the right thing with pthread_mutex_{lock,unlock}() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@913 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 9c8ac6a4..950be406 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -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); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index 4e416362..f65a68e0 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -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); diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 1822ef34..0a5ac84e 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -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) diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 862b0c6f..23442280 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/cache_session.c b/varnish-cache/bin/varnishd/cache_session.c index 0cfea524..f68a9e97 100644 --- a/varnish-cache/bin/varnishd/cache_session.c +++ b/varnish-cache/bin/varnishd/cache_session.c @@ -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); } } diff --git a/varnish-cache/bin/varnishd/cache_vcl.c b/varnish-cache/bin/varnishd/cache_vcl.c index 10b6d4e1..f9c11db6 100644 --- a/varnish-cache/bin/varnishd/cache_vcl.c +++ b/varnish-cache/bin/varnishd/cache_vcl.c @@ -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); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/hash_classic.c b/varnish-cache/bin/varnishd/hash_classic.c index 9cba4e34..f0eca583 100644 --- a/varnish-cache/bin/varnishd/hash_classic.c +++ b/varnish-cache/bin/varnishd/hash_classic.c @@ -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); diff --git a/varnish-cache/bin/varnishd/hash_simple_list.c b/varnish-cache/bin/varnishd/hash_simple_list.c index ce262673..69f3a241 100644 --- a/varnish-cache/bin/varnishd/hash_simple_list.c +++ b/varnish-cache/bin/varnishd/hash_simple_list.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/shmlog.c b/varnish-cache/bin/varnishd/shmlog.c index 7db7d48f..be69874c 100644 --- a/varnish-cache/bin/varnishd/shmlog.c +++ b/varnish-cache/bin/varnishd/shmlog.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index a0521fe7..0db5ced8 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -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); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/include/libvarnish.h b/varnish-cache/include/libvarnish.h index 1580fed4..10a9675a 100644 --- a/varnish-cache/include/libvarnish.h +++ b/varnish-cache/include/libvarnish.h @@ -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))