Commit c02e1b8b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Wrap mutex more completely so that experimentation becomes easier.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1029 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 32d72694
......@@ -439,8 +439,11 @@ int RFC2616_cache_policy(struct sess *sp, struct http *hp);
#define UNLOCKSHM(foo) AZ(pthread_mutex_unlock(foo))
#if 1
#define LOCK(foo) AZ(pthread_mutex_lock(foo))
#define UNLOCK(foo) AZ(pthread_mutex_unlock(foo))
#define MTX pthread_mutex_t
#define MTX_INIT(foo) AZ(pthread_mutex_init(foo, NULL))
#define MTX_DESTROY(foo) AZ(pthread_mutex_destroy(foo))
#define LOCK(foo) AZ(pthread_mutex_lock(foo))
#define UNLOCK(foo) AZ(pthread_mutex_unlock(foo))
#else
#define LOCK(foo) \
do { \
......
......@@ -29,7 +29,7 @@
static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head);
static pthread_mutex_t vbemtx;
static MTX vbemtx;
/*--------------------------------------------------------------------*/
......@@ -293,5 +293,5 @@ void
VBE_Init(void)
{
AZ(pthread_mutex_init(&vbemtx, NULL));
MTX_INIT(&vbemtx);
}
......@@ -70,6 +70,7 @@ CLI_Init(void)
buf = malloc(lbuf);
XXXAN(buf);
nbuf = 0;
printf("CLI ready\n");
while (1) {
pfd[0].fd = heritage.fds[2];
pfd[0].events = POLLIN;
......
......@@ -21,7 +21,7 @@
static pthread_t exp_thread;
static struct binheap *exp_heap;
static pthread_mutex_t exp_mtx;
static MTX exp_mtx;
static unsigned expearly = 30;
static TAILQ_HEAD(,object) exp_deathrow = TAILQ_HEAD_INITIALIZER(exp_deathrow);
......@@ -181,7 +181,7 @@ void
EXP_Init(void)
{
AZ(pthread_mutex_init(&exp_mtx, NULL));
MTX_INIT(&exp_mtx);
exp_heap = binheap_new(NULL, object_cmp, object_update);
XXXAN(exp_heap);
AZ(pthread_create(&exp_thread, NULL, exp_prefetch, NULL));
......
......@@ -60,7 +60,7 @@ HSH_Lookup(struct sess *sp)
XXXAN(w->nobjhead);
w->nobjhead->magic = OBJHEAD_MAGIC;
TAILQ_INIT(&w->nobjhead->objects);
AZ(pthread_mutex_init(&w->nobjhead->mtx, NULL));
MTX_INIT(&w->nobjhead->mtx);
VSL_stats->n_objecthead++;
} else
CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC);
......@@ -209,7 +209,7 @@ HSH_Deref(struct object *o)
if (hash->deref(oh))
return;
assert(TAILQ_EMPTY(&oh->objects));
AZ(pthread_mutex_destroy(&oh->mtx));
MTX_DESTROY(&oh->mtx);
VSL_stats->n_objecthead--;
free(oh);
}
......
......@@ -29,7 +29,7 @@
#include "cli_priv.h"
#include "cache.h"
static pthread_mutex_t wrk_mtx;
static MTX wrk_mtx;
/* Number of work requests queued in excess of worker threads available */
static unsigned wrk_overflow;
......@@ -312,7 +312,7 @@ WRK_Init(void)
pthread_t tp;
int i;
AZ(pthread_mutex_init(&wrk_mtx, NULL));
MTX_INIT(&wrk_mtx);
AZ(pthread_create(&tp, NULL, wrk_reaperthread, NULL));
AZ(pthread_detach(tp));
......
......@@ -57,9 +57,9 @@ static unsigned ses_qp;
TAILQ_HEAD(srcaddrhead ,srcaddr);
static struct srcaddrhead srcaddr_hash[CLIENT_HASH];
static pthread_mutex_t ses_mtx;
static pthread_mutex_t stat_mtx;
static pthread_mutex_t ses_mem_mtx;
static MTX ses_mtx;
static MTX stat_mtx;
static MTX ses_mem_mtx;
/*--------------------------------------------------------------------
* Assign a srcaddr to this session.
......@@ -288,7 +288,7 @@ SES_Init()
for (i = 0; i < CLIENT_HASH; i++)
TAILQ_INIT(&srcaddr_hash[i]);
AZ(pthread_mutex_init(&ses_mtx, NULL));
AZ(pthread_mutex_init(&stat_mtx, NULL));
AZ(pthread_mutex_init(&ses_mem_mtx, NULL));
MTX_INIT(&ses_mtx);
MTX_INIT(&stat_mtx);
MTX_INIT(&ses_mem_mtx);
}
......@@ -37,7 +37,7 @@ static TAILQ_HEAD(, vcls) vcl_head =
static struct vcls *vcl_active; /* protected by vcl_mtx */
static pthread_mutex_t vcl_mtx;
static MTX vcl_mtx;
/*--------------------------------------------------------------------*/
......@@ -284,5 +284,5 @@ void
VCL_Init()
{
AZ(pthread_mutex_init(&vcl_mtx, NULL));
MTX_INIT(&vcl_mtx);
}
......@@ -31,7 +31,7 @@ struct hcl_hd {
unsigned magic;
#define HCL_HEAD_MAGIC 0x0f327016
TAILQ_HEAD(, hcl_entry) head;
pthread_mutex_t mtx;
MTX mtx;
};
static unsigned hcl_nhash = 16383;
......@@ -79,7 +79,7 @@ hcl_start(void)
for (u = 0; u < hcl_nhash; u++) {
TAILQ_INIT(&hcl_head[u].head);
AZ(pthread_mutex_init(&hcl_head[u].mtx, NULL));
MTX_INIT(&hcl_head[u].mtx);
hcl_head[u].magic = HCL_HEAD_MAGIC;
}
}
......
......@@ -22,7 +22,7 @@ struct hsl_entry {
};
static TAILQ_HEAD(, hsl_entry) hsl_head = TAILQ_HEAD_INITIALIZER(hsl_head);
static pthread_mutex_t hsl_mutex;
static MTX hsl_mutex;
/*--------------------------------------------------------------------
* The ->init method is called during process start and allows
......@@ -33,7 +33,7 @@ static void
hsl_start(void)
{
AZ(pthread_mutex_init(&hsl_mutex, NULL));
MTX_INIT(&hsl_mutex);
}
/*--------------------------------------------------------------------
......
......@@ -27,7 +27,7 @@
struct varnish_stats *VSL_stats;
static struct shmloghead *loghead;
static unsigned char *logstart;
static pthread_mutex_t vsl_mtx;
static MTX vsl_mtx;
/*
* This variant copies a byte-range directly to the log, without
......@@ -135,7 +135,7 @@ VSL_Init(void)
assert(loghead->hdrsize == sizeof *loghead);
/* XXX more check sanity of loghead ? */
logstart = (unsigned char *)loghead + loghead->start;
AZ(pthread_mutex_init(&vsl_mtx, NULL));
MTX_INIT(&vsl_mtx);
loghead->starttime = time(NULL);
memset(VSL_stats, 0, sizeof *VSL_stats);
}
......
......@@ -77,7 +77,7 @@ struct smf_sc {
struct smfhead order;
struct smfhead free[NBUCKET];
struct smfhead used;
pthread_mutex_t mtx;
MTX mtx;
};
/*--------------------------------------------------------------------*/
......@@ -492,6 +492,7 @@ new_smf(struct smf_sc *sc, unsigned char *ptr, off_t off, size_t len)
{
struct smf *sp, *sp2;
assert(!(len % sc->pagesize));
sp = calloc(sizeof *sp, 1);
XXXAN(sp);
sp->magic = SMF_MAGIC;
......@@ -534,6 +535,7 @@ smf_open_chunk(struct smf_sc *sc, off_t sz, off_t off, off_t *fail, off_t *sum)
off_t h;
assert(sz != 0);
assert(!(sz % sc->pagesize));
if (*fail < (uintmax_t)sc->pagesize * MINPAGES)
return;
......@@ -576,7 +578,7 @@ smf_open(struct stevedore *st)
/* XXX */
if (sum < MINPAGES * (uintmax_t)getpagesize())
exit (2);
AZ(pthread_mutex_init(&sc->mtx, NULL));
MTX_INIT(&sc->mtx);
}
/*--------------------------------------------------------------------*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment