From 128bb2291b085e97b7ace529475a722313cf0f23 Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Thu, 23 Jul 2015 15:36:19 -0700 Subject: [PATCH] Add mutex LOCK/UNLOCK boilerplate. --- src/microcode/ossmp.h | 40 +++++++++++++++++++++++++++++++++++++--- src/microcode/prossmp.c | 4 ++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/microcode/ossmp.h b/src/microcode/ossmp.h index 5471575cb..c141102dd 100644 --- a/src/microcode/ossmp.h +++ b/src/microcode/ossmp.h @@ -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 */ diff --git a/src/microcode/prossmp.c b/src/microcode/prossmp.c index 7725410c2..eba3173ec 100644 --- a/src/microcode/prossmp.c +++ b/src/microcode/prossmp.c @@ -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); -- 2.25.1