smp: Add mutex LOCK/UNLOCK boilerplate to confshared.h (everywhere).
authorMatt Birkholz <puck@birchwood-abbey.net>
Sat, 20 Dec 2014 18:50:06 +0000 (11:50 -0700)
committerMatt Birkholz <puck@birchwood-abbey.net>
Sun, 21 Dec 2014 19:19:09 +0000 (12:19 -0700)
src/microcode/confshared.h
src/microcode/outf.c
src/microcode/prossmp.c
src/microcode/uxsig.c

index ae091b7f1ee18c732d1e2dbf28864216727a4c52..2b027d89789158ff6f22f46887807b6c95d6f400 100644 (file)
@@ -694,7 +694,59 @@ extern void win32_stack_reset (void);
 #endif
 
 #ifndef ENABLE_SMP
-#define __thread
-#endif
+
+#  define __thread
+#  define LOCK() do { } while (false)
+#  define UNLOCK() do { } while (false)
+
+#else /* ENABLE_SMP */
+
+#  include <pthread.h>
+#  ifdef ENABLE_DEBUGGING_TOOLS
+
+#    define MUTEX_INITIALIZER PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+
+extern bool smp_trace_p;
+
+#    define LOCK() do                                                  \
+{                                                                      \
+  int err;                                                             \
+  if (smp_trace_p && locked_p != false)                                        \
+    outf_error_line (";%d already locked!", self->id);                 \
+  err = pthread_mutex_lock (&mutex);                                   \
+  assert (err == 0);                                                   \
+  locked_p = true;                                                     \
+} while (false)
+
+#    define UNLOCK() do                                                        \
+{                                                                      \
+  int err;                                                             \
+  if (smp_trace_p && locked_p != true)                                 \
+    outf_error_line (";%d already unlocked!", self->id);               \
+  err = pthread_mutex_unlock (&mutex);                                 \
+  assert (err == 0);                                                   \
+  locked_p = false;                                                    \
+} while (false)
+
+#  else /* !ENABLE_DEBUGGING_TOOLS */
+
+#    define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
+
+#    define LOCK() do                                                  \
+{                                                                      \
+  int err = pthread_mutex_lock (&mutex);                               \
+  if (err)                                                             \
+    error_with_argument (err);                                         \
+} while (false)
+
+#    define UNLOCK() do                                                        \
+{                                                                      \
+  int err = pthread_mutex_unlock (&mutex);                             \
+  if (err)                                                             \
+    error_with_argument (err);                                         \
+} while (false)
+
+#  endif /* !ENABLE_DEBUGGING_TOOLS */
+#endif /* ENABLE_SMP */
 
 #endif /* SCM_CONFSHARED_H */
index a5849f9f59bf9d0261f7e5fe198b22b44de7ac1f..b1321b777d1cd7e347baee875fdbb71160a92fc4 100644 (file)
@@ -249,9 +249,11 @@ outf_flush_fatal (void)
 \f
 #ifndef OUTF_VARIANTS_DEFINED
 
+#undef LOCK
+#undef UNLOCK
 #ifdef ENABLE_SMP
-static pthread_mutex_t stderr_mutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_mutex_t stdout_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t stderr_mutex = MUTEX_INITIALIZER;
+static pthread_mutex_t stdout_mutex = MUTEX_INITIALIZER;
 #define LOCK(which) mutex_lock (which)
 #define UNLOCK(which) mutex_unlock (which)
 
index 52be57ccc59595049cf2d1b403960b0e1b3c5276..4e70cbf6d5eac5dd462465c59af8afe932d60160 100644 (file)
@@ -42,7 +42,7 @@ processor_t *processors;
 
 /* The mutex that serializes processor state changes, including the
    gc_processor variable. */
-pthread_mutex_t state_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_mutex_t state_mutex = MUTEX_INITIALIZER;
 
 /* The processor running the garbage collector. */
 processor_t *gc_processor = NULL;
@@ -54,7 +54,7 @@ static pthread_cond_t finished = PTHREAD_COND_INITIALIZER;
 static pthread_cond_t ready = PTHREAD_COND_INITIALIZER;
 
 /* The mutex that serializes thread switches. */
-static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t thread_mutex = MUTEX_INITIALIZER;
 
 /* The current pthread's processor. */
 __thread processor_t *self;
@@ -65,7 +65,7 @@ extern int saved_stack_size;
 
 #ifdef ENABLE_DEBUGGING_TOOLS
 
-static bool smp_trace_p = false;
+bool smp_trace_p = false;
 
 static void
 trace (const char * format, ...)
index 8f061cbf89a683e62126f6add7b76a61399943eb..ce9b208904755389c955a8706dc2a63676265e0e 100644 (file)
@@ -507,7 +507,6 @@ DEFUN_STD_HANDLER (sighnd_console_resize,
 })
 
 #ifdef ENABLE_SMP
-#include <pthread.h>
 
 static
 DEFUN_STD_HANDLER (sighnd_global_gc,
@@ -522,7 +521,7 @@ smp_kill_gc (processor_t *p)
 }
 
 static volatile processor_t *next_timer = NULL;
-static pthread_mutex_t nt_mutex = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t nt_mutex = MUTEX_INITIALIZER;
 #ifdef ENABLE_DEBUGGING_TOOLS
 #  define LOCK_NT() do                                                 \
 {                                                                      \