qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe


From: Fam Zheng
Subject: Re: [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe
Date: Wed, 11 Jun 2014 14:59:11 +0800
User-agent: Mutt/1.5.23 (2014-03-12)

On Tue, 06/03 18:39, Paolo Bonzini wrote:
> diff --git a/qemu-char.c b/qemu-char.c
> index b478a3d..dcd0765 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -121,7 +121,12 @@ void qemu_chr_be_generic_open(CharDriverState *s)
>  
>  int qemu_chr_fe_write(CharDriverState *s, const uint8_t *buf, int len)
>  {
> -    return s->chr_write(s, buf, len);
> +    int ret;
> +
> +    qemu_mutex_lock(&s->chr_write_lock);
> +    ret = s->chr_write(s, buf, len);
> +    qemu_mutex_unlock(&s->chr_write_lock);
> +    return ret;
>  }
>  
>  int qemu_chr_fe_write_all(CharDriverState *s, const uint8_t *buf, int len)
> @@ -129,6 +134,7 @@ int qemu_chr_fe_write_all(CharDriverState *s, const 
> uint8_t *buf, int len)
>      int offset = 0;
>      int res;
>  
> +    qemu_mutex_lock(&s->chr_write_lock);
>      while (offset < len) {
>          do {
>              res = s->chr_write(s, buf + offset, len - offset);
> @@ -147,6 +153,7 @@ int qemu_chr_fe_write_all(CharDriverState *s, const 
> uint8_t *buf, int len)

More context in the loop:

              if (res == -1 && errno == EAGAIN) {
                  g_usleep(100);
              }
          } while (res == -1 && errno == EAGAIN);

          if (res == 0) {
              break;
          }

          if (res < 0) {
(*)           return res;
          }

Doesn't (*) need an unlock?


Fam
>  
>          offset += res;
>      }
> +    qemu_mutex_unlock(&s->chr_write_lock);
>  
>      return offset;
>  }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]