From d3015d912539fc7ba1a3f8298712fbda7acec429 Mon Sep 17 00:00:00 2001
From: Jonas Wallden <jonasw@roxen.com>
Date: Tue, 18 Apr 2000 08:54:13 +0200
Subject: [PATCH] Always initialize mutex and condition variables before use.

Rev: src/modules/Gdbm/gdbmmod.c:1.9
Rev: src/modules/HTTPLoop/accept_and_parse.c:1.11
Rev: src/modules/HTTPLoop/cache.c:1.8
Rev: src/modules/Msql/msqlmod.c:1.12
Rev: src/modules/Postgres/pgresult.c:1.12
Rev: src/modules/Postgres/postgres.c:1.17
Rev: src/modules/spider/spider.c:1.90
Rev: src/threads.c:1.120
Rev: src/threads.h:1.84
---
 src/modules/Gdbm/gdbmmod.c              |  4 ++--
 src/modules/HTTPLoop/accept_and_parse.c |  8 +++++---
 src/modules/HTTPLoop/cache.c            |  4 ++--
 src/modules/Msql/msqlmod.c              |  6 +++---
 src/modules/Postgres/pgresult.c         |  6 +++---
 src/modules/Postgres/postgres.c         |  4 ++--
 src/modules/spider/spider.c             |  4 ++--
 src/threads.c                           |  4 ++--
 src/threads.h                           | 17 ++++++++++++++++-
 9 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/modules/Gdbm/gdbmmod.c b/src/modules/Gdbm/gdbmmod.c
index 490286136b..bfccd2e7df 100644
--- a/src/modules/Gdbm/gdbmmod.c
+++ b/src/modules/Gdbm/gdbmmod.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: gdbmmod.c,v 1.8 1999/06/19 20:20:38 hubbe Exp $");
+RCSID("$Id: gdbmmod.c,v 1.9 2000/04/18 06:53:53 jonasw Exp $");
 #include "gdbm_machine.h"
 #include "threads.h"
 
@@ -22,7 +22,7 @@ RCSID("$Id: gdbmmod.c,v 1.8 1999/06/19 20:20:38 hubbe Exp $");
 #include <gdbm.h>
 
 #ifdef _REENTRANT
-static MUTEX_T gdbm_lock;
+static MUTEX_T gdbm_lock STATIC_MUTEX_INIT;
 #endif  
 
 struct gdbm_glue
diff --git a/src/modules/HTTPLoop/accept_and_parse.c b/src/modules/HTTPLoop/accept_and_parse.c
index 50e65901ab..04a9968088 100644
--- a/src/modules/HTTPLoop/accept_and_parse.c
+++ b/src/modules/HTTPLoop/accept_and_parse.c
@@ -70,10 +70,10 @@ struct program *accept_loop_program;
 #endif
 
 #define MAXLEN (1024*1024*10)
-static MUTEX_T queue_mutex;
+static MUTEX_T queue_mutex STATIC_MUTEX_INIT;
 static struct args *request, *last;
 
-static MUTEX_T arg_lock;
+static MUTEX_T arg_lock STATIC_MUTEX_INIT;
 static int next_free_arg, num_args;
 static struct args *free_arg_list[100];
 
@@ -584,14 +584,16 @@ static void f_accept_with_http_parse(INT32 nargs)
   {
     struct log *log = aap_malloc(sizeof(struct log));
     MEMSET(log, 0, sizeof(struct log));
+    mt_init(&log->log_lock);
     args->log = log;
     log->next = aap_first_log;
     aap_first_log = log;
   }
   c = aap_malloc(sizeof(struct cache));
+  MEMSET(c, 0, sizeof(struct cache));
+  mt_init(&c->mutex);
   c->next = first_cache;
   first_cache = c;
-  MEMSET(c, 0, sizeof(struct cache));
   args->cache = c;
   c->max_size = ms;
   args->fd = ((struct port *)port->storage)->fd;
diff --git a/src/modules/HTTPLoop/cache.c b/src/modules/HTTPLoop/cache.c
index 9225dd6748..5af3cc8b4e 100644
--- a/src/modules/HTTPLoop/cache.c
+++ b/src/modules/HTTPLoop/cache.c
@@ -30,9 +30,9 @@ struct cache *first_cache;
 
 static struct pike_string *free_queue[1024];
 static int numtofree;
-static MUTEX_T tofree_mutex;
+static MUTEX_T tofree_mutex STATIC_MUTEX_INIT;
 
-static MUTEX_T cache_entry_lock;
+static MUTEX_T cache_entry_lock STATIC_MUTEX_INIT;
 int next_free_ce, num_cache_entries;
 struct cache_entry *free_cache_entries[1024];
 
diff --git a/src/modules/Msql/msqlmod.c b/src/modules/Msql/msqlmod.c
index 739d39a4dc..c3e7ef726e 100644
--- a/src/modules/Msql/msqlmod.c
+++ b/src/modules/Msql/msqlmod.c
@@ -2,7 +2,7 @@
  * This code is (C) Francesco Chemolli, 1997.
  * You may use, modify and redistribute it freely under the terms
  * of the GNU General Public License, version 2.
- * $Id: msqlmod.c,v 1.11 2000/04/13 18:37:16 grubba Exp $
+ * $Id: msqlmod.c,v 1.12 2000/04/18 06:54:05 jonasw Exp $
  *
  * This version is intended for Pike/0.5 and later.
  * It won't compile under older versions of the Pike interpreter.
@@ -35,11 +35,11 @@
 #include "operators.h"
 #include "multiset.h"
 
-RCSID("$Id: msqlmod.c,v 1.11 2000/04/13 18:37:16 grubba Exp $");
+RCSID("$Id: msqlmod.c,v 1.12 2000/04/18 06:54:05 jonasw Exp $");
 #include "version.h"
 
 #ifdef _REENTRANT
-MUTEX_T pike_msql_mutex;
+MUTEX_T pike_msql_mutex STATIC_MUTEX_INIT;
 #define MSQL_LOCK() mt_lock(&pike_msql_mutex)
 #define MSQL_UNLOCK() mt_unlock(&pike_msql_mutex)
 #else
diff --git a/src/modules/Postgres/pgresult.c b/src/modules/Postgres/pgresult.c
index ad3969d9fb..3b66d122c1 100644
--- a/src/modules/Postgres/pgresult.c
+++ b/src/modules/Postgres/pgresult.c
@@ -1,5 +1,5 @@
 /*
- * $Id: pgresult.c,v 1.11 1999/04/30 07:22:52 hubbe Exp $
+ * $Id: pgresult.c,v 1.12 2000/04/18 06:54:08 jonasw Exp $
  *
  * Postgres95 support for pike/0.5 and up
  *
@@ -63,10 +63,10 @@
 #include "builtin_functions.h"
 #include "module_support.h"
 
-RCSID("$Id: pgresult.c,v 1.11 1999/04/30 07:22:52 hubbe Exp $");
+RCSID("$Id: pgresult.c,v 1.12 2000/04/18 06:54:08 jonasw Exp $");
 
 #ifdef _REENTRANT
-MUTEX_T pike_postgres_result_mutex;
+MUTEX_T pike_postgres_result_mutex STATIC_MUTEX_INIT;
 #define PQ_LOCK() mt_lock(&pike_postgres_mutex)
 #define PQ_UNLOCK() mt_unlock(&pike_postgres_mutex)
 #else
diff --git a/src/modules/Postgres/postgres.c b/src/modules/Postgres/postgres.c
index 0fd5b18004..a8f5deeb20 100644
--- a/src/modules/Postgres/postgres.c
+++ b/src/modules/Postgres/postgres.c
@@ -38,7 +38,7 @@
 
 /* Actual code */
 #ifdef _REENTRANT
-MUTEX_T pike_postgres_mutex;
+MUTEX_T pike_postgres_mutex STATIC_MUTEX_INIT;
 #define PQ_LOCK() mt_lock(&pike_postgres_mutex);
 #define PQ_UNLOCK() mt_unlock(&pike_postgres_mutex);
 #else
@@ -56,7 +56,7 @@ static void pgdebug (char * a, ...) {}
 
 struct program * postgres_program;
 
-RCSID("$Id: postgres.c,v 1.16 2000/04/04 14:18:51 grubba Exp $");
+RCSID("$Id: postgres.c,v 1.17 2000/04/18 06:54:08 jonasw Exp $");
 
 #define THIS ((struct pgres_object_data *) fp->current_storage)
 
diff --git a/src/modules/spider/spider.c b/src/modules/spider/spider.c
index b6a0b44484..c71080326b 100644
--- a/src/modules/spider/spider.c
+++ b/src/modules/spider/spider.c
@@ -43,7 +43,7 @@
 #include "threads.h"
 #include "operators.h"
 
-RCSID("$Id: spider.c,v 1.89 2000/02/16 04:00:18 per Exp $");
+RCSID("$Id: spider.c,v 1.90 2000/04/18 06:54:13 jonasw Exp $");
 
 #ifdef HAVE_PWD_H
 #include <pwd.h>
@@ -1146,7 +1146,7 @@ struct thread_args
   char buffer[BUFFER];
 };
 
-MUTEX_T done_lock;
+MUTEX_T done_lock STATIC_MUTEX_INIT;
 struct thread_args *done;
 
 /* WARNING! This function is running _without_ any stack etc. */
diff --git a/src/threads.c b/src/threads.c
index 23d3b57ad6..ab0a7bb58a 100644
--- a/src/threads.c
+++ b/src/threads.c
@@ -1,5 +1,5 @@
 #include "global.h"
-RCSID("$Id: threads.c,v 1.119 2000/04/15 05:05:28 hubbe Exp $");
+RCSID("$Id: threads.c,v 1.120 2000/04/18 06:53:48 jonasw Exp $");
 
 int num_threads = 1;
 int threads_disabled = 0;
@@ -1359,7 +1359,7 @@ static struct farmer {
   COND_T harvest_moon;
 } *farmers;
 
-static MUTEX_T rosie;
+static MUTEX_T rosie STATIC_MUTEX_INIT;
 
 static TH_RETURN_TYPE farm(void *_a)
 {
diff --git a/src/threads.h b/src/threads.h
index 0fb6dcb4b5..d77e97e9ce 100644
--- a/src/threads.h
+++ b/src/threads.h
@@ -1,5 +1,5 @@
 /*
- * $Id: threads.h,v 1.83 2000/04/17 18:47:44 mast Exp $
+ * $Id: threads.h,v 1.84 2000/04/18 06:53:48 jonasw Exp $
  */
 #ifndef THREADS_H
 #define THREADS_H
@@ -656,4 +656,19 @@ extern int thread_storage_offset;
 #define MUTEX_T PIKE_MUTEX_T
 #endif
 
+
+/* Initializer macros for static mutex and condition variables */
+#ifdef PTHREAD_MUTEX_INITIALIZER
+#define STATIC_MUTEX_INIT  = PTHREAD_MUTEX_INITIALIZER
+#else
+#define STATIC_MUTEX_INIT
+#endif
+#ifdef PTHREAD_COND_INITIALIZER
+#define STATIC_COND_INIT   = PTHREAD_COND_INITIALIZER
+#else
+#define STATIC_COND_INIT
+#endif
+
+
+
 #endif /* THREADS_H */
-- 
GitLab