Commit 98204cba authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent cc8fb90e
......@@ -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);
......
......@@ -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__()
......
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