r3605 - branches/2.0/varnish-cache/bin/varnishd
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Thu Feb 5 11:59:02 CET 2009
Author: tfheen
Date: 2009-02-05 11:59:01 +0100 (Thu, 05 Feb 2009)
New Revision: 3605
Modified:
branches/2.0/varnish-cache/bin/varnishd/cache_lck.c
Log:
Merge r3384+r3385:
Have I mentioned that I think POSIX is a bunch of amateurs ?
There is no NULL value for pthread_t and you have to call a function
to compare them.
Remember to set lock "held" in CondWait
Modified: branches/2.0/varnish-cache/bin/varnishd/cache_lck.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-05 10:37:46 UTC (rev 3604)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-05 10:59:01 UTC (rev 3605)
@@ -52,6 +52,7 @@
unsigned magic;
#define ILCK_MAGIC 0x7b86c8a5
pthread_mutex_t mtx;
+ int held;
pthread_t owner;
VTAILQ_ENTRY(ilck) list;
const char *w;
@@ -71,8 +72,9 @@
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
if (!(params->diag_bitmap & 0x18)) {
AZ(pthread_mutex_lock(&ilck->mtx));
- AZ(ilck->owner);
+ AZ(ilck->held);
ilck->owner = pthread_self();
+ ilck->held = 1;
return;
}
r = pthread_mutex_trylock(&ilck->mtx);
@@ -83,8 +85,9 @@
} else if (params->diag_bitmap & 0x8) {
VSL(SLT_Debug, 0, "MTX_LOCK(%s,%s,%d,%s)", p, f, l, ilck->w);
}
- AZ(ilck->owner);
+ AZ(ilck->held);
ilck->owner = pthread_self();
+ ilck->held = 1;
}
void
@@ -93,8 +96,9 @@
struct ilck *ilck;
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
- assert(ilck->owner == pthread_self());
- ilck->owner = NULL;
+ assert(pthread_equal(ilck->owner, pthread_self()));
+ AN(ilck->held);
+ ilck->held = 0;
AZ(pthread_mutex_unlock(&ilck->mtx));
if (params->diag_bitmap & 0x8)
VSL(SLT_Debug, 0, "MTX_UNLOCK(%s,%s,%d,%s)", p, f, l, ilck->w);
@@ -113,7 +117,8 @@
VSL(SLT_Debug, 0,
"MTX_TRYLOCK(%s,%s,%d,%s) = %d", p, f, l, ilck->w);
if (r == 0) {
- AZ(ilck->owner);
+ AZ(ilck->held);
+ ilck->held = 1;
ilck->owner = pthread_self();
}
return (r);
@@ -126,9 +131,11 @@
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
if (held)
- assert(ilck->owner == pthread_self());
+ assert(ilck->held &&
+ pthread_equal(ilck->owner, pthread_self()));
else
- assert(ilck->owner != pthread_self());
+ assert(!ilck->held ||
+ !pthread_equal(ilck->owner, pthread_self()));
}
void
@@ -137,10 +144,12 @@
struct ilck *ilck;
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
- assert(ilck->owner == pthread_self());
- ilck->owner = NULL;
+ AN(ilck->held);
+ assert(pthread_equal(ilck->owner, pthread_self()));
+ ilck->held = 0;
AZ(pthread_cond_wait(cond, &ilck->mtx));
- AZ(ilck->owner);
+ AZ(ilck->held);
+ ilck->held = 1;
ilck->owner = pthread_self();
}
More information about the varnish-commit
mailing list