Add mutex LOCK/UNLOCK boilerplate.
authorMatt Birkholz <puck@birchwood-abbey.net>
Thu, 23 Jul 2015 22:36:19 +0000 (15:36 -0700)
committerMatt Birkholz <puck@birchwood-abbey.net>
Thu, 26 Nov 2015 08:09:46 +0000 (01:09 -0700)
src/microcode/ossmp.h
src/microcode/prossmp.c

index 5471575cb2d903b265d2eec38a074211ebc87d3b..c141102ddf7a246271e904373242c0c236a6b2d1 100644 (file)
@@ -61,6 +61,9 @@ extern processor_t *processors;
 extern __thread processor_t *self;
 extern processor_t *gc_processor;
 
+extern void mutex_lock (pthread_mutex_t *mutex);
+extern void mutex_unlock (pthread_mutex_t *mutex);
+
 extern void setup_processors (int count);
 extern void start_processors (void);
 
@@ -76,12 +79,43 @@ extern bool smp_trace_p;
 
 #define MUTEX_INITIALIZER PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
 
-#else
+#define LOCK() do                                                      \
+{                                                                      \
+  if (smp_trace_p && locked_p != false)                                        \
+    outf_error_line (";%d already locked!", self->id);                 \
+  mutex_lock (&mutex);                                                 \
+  locked_p = true;                                                     \
+} while (false)
+
+#define UNLOCK() do                                                    \
+{                                                                      \
+  if (smp_trace_p && locked_p != true)                                 \
+    outf_error_line (";%d already unlocked!", self->id);               \
+  mutex_unlock (&mutex);                                               \
+  locked_p = false;                                                    \
+} while (false)
+
+#else /* !ENABLE_DEBUGGING_TOOLS */
 
 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
 
-#endif
+#define LOCK() do                                                      \
+{                                                                      \
+  mutex_lock (&mutex);                                                 \
+} while (false)
+
+#define UNLOCK() do                                                    \
+{                                                                      \
+  mutex_unlock (&mutex);                                               \
+} while (false)
+
+#endif /* !ENABLE_DEBUGGING_TOOLS */
+
+#else /* !ENABLE_SMP */
+
+#define LOCK() do { } while (false)
+#define UNLOCK() do { } while (false)
 
-#endif /* ENABLE_SMP */
+#endif /* !ENABLE_SMP */
 
 #endif /* SCM_OSSMP_H */
index 7725410c22db21e62fc1a66d52d6332abe3ba317..eba3173eca05c275f7803353e25f6102c4c6856d 100644 (file)
@@ -102,7 +102,7 @@ fatal (const char * format, ...)
 
 static void pthread_error (int code);
 
-static void
+void
 mutex_lock (pthread_mutex_t *mutex)
 {
   int err = pthread_mutex_lock (mutex);
@@ -113,7 +113,7 @@ mutex_lock (pthread_mutex_t *mutex)
     }
 }
 
-static void
+void
 mutex_unlock (pthread_mutex_t *mutex)
 {
   int err = pthread_mutex_unlock (mutex);