Justus Winter, le Wed 12 Mar 2014 15:55:49 +0100, a écrit :
> * mach-defpager/default_pager.c (synchronized_printf): New function.
> (printf_lock): Move to synchronized_printf.
> (dprintf): Use synchronized_printf.
> (ddprintf): Likewise.

Ack.

> ---
>  mach-defpager/default_pager.c | 29 ++++++++++++++++++-----------
>  1 file changed, 18 insertions(+), 11 deletions(-)
> 
> diff --git a/mach-defpager/default_pager.c b/mach-defpager/default_pager.c
> index df0200d..ebbff60 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
> -- 
> 1.9.0
> 

-- 
Samuel
War doesn't prove who's right, just who's left.

Reply via email to