diff options
author | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-03-12 12:20:00 +0100 |
---|---|---|
committer | Justus Winter <4winter@informatik.uni-hamburg.de> | 2014-03-12 12:20:00 +0100 |
commit | 727d2825675e9d67999a15d2e9903bf8af854395 (patch) | |
tree | 1828dda6f899128d55673f58edc21c5f1af255ff /mach-defpager | |
parent | 6f1fa0884602c05fba05c14cd6eb6884ba928e8e (diff) |
mach-defpager: add and use synchronized_printf for dprintf
* mach-defpager/default_pager.c (synchronized_printf): New function.
(printf_lock): Move to synchronized_printf.
(dprintf): Use synchronized_printf.
(ddprintf): Likewise.
Diffstat (limited to 'mach-defpager')
-rw-r--r-- | mach-defpager/default_pager.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c index df0200d8..ebbff608 100644 --- a/mach-defpager/default_pager.c +++ b/mach-defpager/default_pager.c @@ -51,6 +51,7 @@ #include <errno.h> #include <stdio.h> #include <string.h> +#include <stdarg.h> #include <file_io.h> @@ -63,24 +64,30 @@ static char my_name[] = "(default pager):"; -static pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER; +static void __attribute__ ((format (printf, 1, 2), unused)) +synchronized_printf (const char *fmt, ...) +{ + static pthread_mutex_t printf_lock = PTHREAD_MUTEX_INITIALIZER; + va_list ap; + + va_start (ap, fmt); + pthread_mutex_lock (&printf_lock); + + vprintf (fmt, ap); + fflush (stdout); + + pthread_mutex_unlock (&printf_lock); + va_end (ap); +} #if 0 -#define dprintf(f, x...) \ - ({ pthread_mutex_lock (&printf_lock); \ - printf (f , ##x); \ - fflush (stdout); \ - pthread_mutex_unlock (&printf_lock); }) +#define dprintf(f, x...) synchronized_printf (f, ##x) #else #define dprintf(f, x...) #endif #if 0 -#define ddprintf(f, x...) \ - ({ pthread_mutex_lock (&printf_lock); \ - printf (f , ##x); \ - fflush (stdout); \ - pthread_mutex_unlock (&printf_lock); }) +#define ddprintf(f, x...) synchronized_printf (f, ##x) #else #define ddprintf(f, x...) #endif |