#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 */
\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)
/* 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;
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;
#ifdef ENABLE_DEBUGGING_TOOLS
-static bool smp_trace_p = false;
+bool smp_trace_p = false;
static void
trace (const char * format, ...)
})
#ifdef ENABLE_SMP
-#include <pthread.h>
static
DEFUN_STD_HANDLER (sighnd_global_gc,
}
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 \
{ \