[master] d6ad7f2 Initialise mutexes explicitly

Federico G. Schwindt fgsch at lodoss.net
Thu Jul 6 02:01:06 CEST 2017


commit d6ad7f2169adddffb3d99def1fa2354141f28abc
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Thu Jul 6 00:36:26 2017 +0100

    Initialise mutexes explicitly

diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 8c3df12..9957b3e 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -58,7 +58,7 @@
  */
 
 static struct vsb pan_vsb_storage, *pan_vsb;
-static pthread_mutex_t panicstr_mtx = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t panicstr_mtx;
 
 static void pan_sess(struct vsb *, const struct sess *);
 
@@ -690,6 +690,7 @@ void
 PAN_Init(void)
 {
 
+	AZ(pthread_mutex_init(&panicstr_mtx, NULL));
 	VAS_Fail = pan_ic;
 	pan_vsb = &pan_vsb_storage;
 	AN(heritage.panic_str);
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index f8253cc..fb280af 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -43,6 +43,8 @@
 #include "vrt_obj.h"
 
 
+static pthread_mutex_t stv_mtx;
+
 /*--------------------------------------------------------------------
  * XXX: trust pointer writes to be atomic
  */
@@ -52,9 +54,8 @@ STV_next()
 {
 	static struct stevedore *stv;
 	struct stevedore *r;
-	static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
 
-	AZ(pthread_mutex_lock(&mtx));
+	AZ(pthread_mutex_lock(&stv_mtx));
 	if (!STV__iter(&stv))
 		AN(STV__iter(&stv));
 	if (stv == stv_transient) {
@@ -62,7 +63,7 @@ STV_next()
 		AN(STV__iter(&stv));
 	}
 	r = stv;
-	AZ(pthread_mutex_unlock(&mtx));
+	AZ(pthread_mutex_unlock(&stv_mtx));
 	AN(r);
 	return (r);
 }
@@ -102,6 +103,7 @@ STV_open(void)
 	char buf[1024];
 
 	ASSERT_CLI();
+	AZ(pthread_mutex_init(&stv_mtx, NULL));
 	STV_Foreach(stv) {
 		bprintf(buf, "storage.%s", stv->ident);
 		stv->vclname = strdup(buf);



More information about the varnish-commit mailing list