[master] 98204cb Make Lck_AssertHeld trigger in the caller's code
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Thu Dec 1 17:00:06 CET 2016
commit 98204cba8484aec3991ee048a553db3241a19761
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Thu Feb 25 15:09:52 2016 +0100
Make Lck_AssertHeld trigger in the caller's code
The `held == 0` branch in the Lck__AssertHeld function is *never*
taken and `cache.h` instructs to only use the macro. Being generated
from calling code, the panic message becomes more informative.
Panic messages were up until now not very helpful:
Assert error in Lck__Assert(), cache/cache_lck.c line 175:
Condition(ilck->held) not true.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index d71504e..87ccdd6 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -840,7 +840,8 @@ void Lck__Lock(struct lock *lck, const char *p, int l);
void Lck__Unlock(struct lock *lck, const char *p, int l);
int Lck__Trylock(struct lock *lck, const char *p, int l);
void Lck__New(struct lock *lck, struct VSC_C_lck *, const char *);
-void Lck__Assert(const struct lock *lck, int held);
+int Lck__Held(const struct lock *lck);
+int Lck__Owned(const struct lock *lck);
/* public interface: */
void Lck_Delete(struct lock *lck);
@@ -850,7 +851,11 @@ int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double);
#define Lck_Lock(a) Lck__Lock(a, __func__, __LINE__)
#define Lck_Unlock(a) Lck__Unlock(a, __func__, __LINE__)
#define Lck_Trylock(a) Lck__Trylock(a, __func__, __LINE__)
-#define Lck_AssertHeld(a) Lck__Assert(a, 1)
+#define Lck_AssertHeld(a) \
+ do { \
+ assert(Lck__Held(a)); \
+ assert(Lck__Owned(a)); \
+ } while (0)
struct VSC_C_lck *Lck_CreateClass(const char *name);
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 90190dc..03dd243 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -165,19 +165,23 @@ Lck__Trylock(struct lock *lck, const char *p, int l)
return (r);
}
-void
-Lck__Assert(const struct lock *lck, int held)
+int
+Lck__Held(const struct lock *lck)
{
struct ilck *ilck;
CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
- if (held) {
- assert(ilck->held);
- assert(pthread_equal(ilck->owner, pthread_self()));
- } else {
- AZ(ilck->held);
- AZ(pthread_equal(ilck->owner, pthread_self()));
- }
+ return (ilck->held);
+}
+
+int
+Lck__Owned(const struct lock *lck)
+{
+ struct ilck *ilck;
+
+ CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC);
+ AN(ilck->held);
+ return (pthread_equal(ilck->owner, pthread_self()));
}
int __match_proto__()
More information about the varnish-commit
mailing list