[master] 835b508 Switch to PTHREAD_MUTEX_ERRORCHECK mutexen.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Feb 5 10:04:09 CET 2015
commit 835b5088dc8823323bec7427514a3c08c7a4586e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Feb 5 09:01:59 2015 +0000
Switch to PTHREAD_MUTEX_ERRORCHECK mutexen.
This is very unlikely to make any difference, but the sheer stupidity
fot he PTHREAD_MUTEX_NORMAL definition is ubearable, now that I've
become aware of it.
Inspired by: CERT secure coding POS04-C
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index 288d452..b35b629 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -53,6 +53,8 @@ struct ilck {
struct VSC_C_lck *stat;
};
+static pthread_mutexattr_t attr;
+
static VTAILQ_HEAD(, ilck) ilck_head =
VTAILQ_HEAD_INITIALIZER(ilck_head);
@@ -177,7 +179,7 @@ Lck__New(struct lock *lck, struct VSC_C_lck *st, const char *w)
ilck->w = w;
ilck->stat = st;
ilck->stat->creat++;
- AZ(pthread_mutex_init(&ilck->mtx, NULL));
+ AZ(pthread_mutex_init(&ilck->mtx, &attr));
AZ(pthread_mutex_lock(&lck_mtx));
VTAILQ_INSERT_TAIL(&ilck_head, ilck, list);
AZ(pthread_mutex_unlock(&lck_mtx));
@@ -207,7 +209,9 @@ void
LCK_Init(void)
{
- AZ(pthread_mutex_init(&lck_mtx, NULL));
+ AZ(pthread_mutexattr_init(&attr));
+ AZ(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
+ AZ(pthread_mutex_init(&lck_mtx, &attr));
#define LOCK(nam) \
lck_##nam = VSM_Alloc(sizeof(struct VSC_C_lck), \
VSC_CLASS, VSC_type_lck, #nam);
More information about the varnish-commit
mailing list