Use outf where you would normally think of using fprintf and
outf_flush where you would normally use fflush. */
-#include "config.h"
+#include "scheme.h"
#include "outf.h"
#ifdef __WIN32__
\f
#ifndef OUTF_VARIANTS_DEFINED
+#ifdef ENABLE_SMP
+static pthread_mutex_t stderr_mutex = MUTEX_INITIALIZER;
+static pthread_mutex_t stdout_mutex = MUTEX_INITIALIZER;
+#define LOCKN(which) mutex_lock_noerr (which)
+#define UNLOCKN(which) mutex_unlock_noerr (which)
+
+static void
+mutex_lock_noerr (pthread_mutex_t *m)
+{
+ int err = pthread_mutex_lock (m);
+ if (err)
+ outf_error_line (";%d outf mutex lock failed: %d", self->id, err);
+}
+
+static void
+mutex_unlock_noerr (pthread_mutex_t *m)
+{
+ int err = pthread_mutex_unlock (m);
+ if (err)
+ outf_error_line (";%d outf mutex unlock failed: %d", self->id, err);
+}
+
+#else
+#define LOCKN(which)
+#define UNLOCKN(which)
+#endif
+
void
voutf_console (const char * format, va_list args)
{
+ LOCKN (&stdout_mutex);
vfprintf (stdout, format, args);
+ UNLOCKN (&stdout_mutex);
}
void
outf_flush_console (void)
{
+ LOCKN (&stdout_mutex);
fflush (stdout);
+ UNLOCKN (&stdout_mutex);
}
void
voutf_error (const char * format, va_list args)
{
+ LOCKN (&stderr_mutex);
vfprintf (stderr, format, args);
+ UNLOCKN (&stderr_mutex);
}
void
outf_flush_error (void)
{
+ LOCKN (&stderr_mutex);
fflush (stderr);
+ UNLOCKN (&stderr_mutex);
}
void
voutf_error_line (const char * format, va_list args)
{
+ LOCKN (&stderr_mutex);
vfprintf (stderr, format, args);
fputc ('\n', stderr);
fflush (stderr);
+ UNLOCKN (&stderr_mutex);
}
void
voutf_fatal (const char * format, va_list args)
{
+ LOCKN (&stderr_mutex);
vfprintf (stderr, format, args);
+ UNLOCKN (&stderr_mutex);
}
void
outf_flush_fatal (void)
{
+ LOCKN (&stderr_mutex);
fflush (stderr);
+ UNLOCKN (&stderr_mutex);
}
#endif /* not OUTF_VARIANTS_DEFINED */