From 94985d89b460fce351bac9973b4ecbb8d456b36f Mon Sep 17 00:00:00 2001 From: phk Date: Sat, 16 Sep 2006 15:54:56 +0000 Subject: [PATCH] Wrap mutex more completely so that experimentation becomes easier. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1029 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 7 +++++-- varnish-cache/bin/varnishd/cache_backend.c | 4 ++-- varnish-cache/bin/varnishd/cache_cli.c | 1 + varnish-cache/bin/varnishd/cache_expire.c | 4 ++-- varnish-cache/bin/varnishd/cache_hash.c | 4 ++-- varnish-cache/bin/varnishd/cache_pool.c | 4 ++-- varnish-cache/bin/varnishd/cache_session.c | 12 ++++++------ varnish-cache/bin/varnishd/cache_vcl.c | 4 ++-- varnish-cache/bin/varnishd/hash_classic.c | 4 ++-- varnish-cache/bin/varnishd/hash_simple_list.c | 4 ++-- varnish-cache/bin/varnishd/shmlog.c | 4 ++-- varnish-cache/bin/varnishd/storage_file.c | 6 ++++-- 12 files changed, 32 insertions(+), 26 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index b9d9bea3..28973e91 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -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 { \ diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index d4f769ac..6033b54b 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/cache_cli.c b/varnish-cache/bin/varnishd/cache_cli.c index 56b8503f..21793260 100644 --- a/varnish-cache/bin/varnishd/cache_cli.c +++ b/varnish-cache/bin/varnishd/cache_cli.c @@ -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; diff --git a/varnish-cache/bin/varnishd/cache_expire.c b/varnish-cache/bin/varnishd/cache_expire.c index 0699178c..90c8207f 100644 --- a/varnish-cache/bin/varnishd/cache_expire.c +++ b/varnish-cache/bin/varnishd/cache_expire.c @@ -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)); diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 54010656..cda1381f 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 75de3979..eb1b200a 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -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)); diff --git a/varnish-cache/bin/varnishd/cache_session.c b/varnish-cache/bin/varnishd/cache_session.c index 0e9ed0ca..d2deff01 100644 --- a/varnish-cache/bin/varnishd/cache_session.c +++ b/varnish-cache/bin/varnishd/cache_session.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/cache_vcl.c b/varnish-cache/bin/varnishd/cache_vcl.c index 377ed4d9..19647b32 100644 --- a/varnish-cache/bin/varnishd/cache_vcl.c +++ b/varnish-cache/bin/varnishd/cache_vcl.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/hash_classic.c b/varnish-cache/bin/varnishd/hash_classic.c index 34096775..088c7d24 100644 --- a/varnish-cache/bin/varnishd/hash_classic.c +++ b/varnish-cache/bin/varnishd/hash_classic.c @@ -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; } } diff --git a/varnish-cache/bin/varnishd/hash_simple_list.c b/varnish-cache/bin/varnishd/hash_simple_list.c index 89eb89ca..54a6c0f2 100644 --- a/varnish-cache/bin/varnishd/hash_simple_list.c +++ b/varnish-cache/bin/varnishd/hash_simple_list.c @@ -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); } /*-------------------------------------------------------------------- diff --git a/varnish-cache/bin/varnishd/shmlog.c b/varnish-cache/bin/varnishd/shmlog.c index 4c988a59..892a0ce1 100644 --- a/varnish-cache/bin/varnishd/shmlog.c +++ b/varnish-cache/bin/varnishd/shmlog.c @@ -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); } diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index ac4a8465..8a966fd9 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -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); } /*--------------------------------------------------------------------*/ -- 2.39.5