From: Matt Birkholz Date: Thu, 23 Jul 2015 22:36:19 +0000 (-0700) Subject: Add mutex LOCK/UNLOCK boilerplate. X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=128bb2291b085e97b7ace529475a722313cf0f23;p=mit-scheme.git Add mutex LOCK/UNLOCK boilerplate. --- 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);