qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: kwolf@redhat.com, kraxel@redhat.com, qemu-devel@nongnu.org,
	stefanha@redhat.com, lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe
Date: Wed, 11 Jun 2014 10:16:29 +0200	[thread overview]
Message-ID: <5398105D.6090701@redhat.com> (raw)
In-Reply-To: <20140611065911.GG5448@T430.nay.redhat.com>

Il 11/06/2014 08:59, Fam Zheng ha scritto:
> 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?

Indeed, thanks.

Paolo

  reply	other threads:[~2014-06-11  8:16 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-03 16:39 [Qemu-devel] [PATCH 0/5] qemu-char/monitor: make monitor_puts thread safe Paolo Bonzini
2014-06-03 16:39 ` [Qemu-devel] [PATCH 1/6] qemu-char: introduce qemu_chr_alloc Paolo Bonzini
2014-06-11  6:28   ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 2/6] qemu-char: do not call chr_write directly Paolo Bonzini
2014-06-11  6:30   ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 3/6] qemu-char: move pty_chr_update_read_handler around Paolo Bonzini
2014-06-11  6:32   ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe Paolo Bonzini
2014-06-11  6:59   ` Fam Zheng
2014-06-11  8:16     ` Paolo Bonzini [this message]
2014-06-03 16:39 ` [Qemu-devel] [PATCH 5/6] monitor: protect outbuf with mutex Paolo Bonzini
2014-06-10 14:10   ` Luiz Capitulino
2014-06-10 14:24     ` Paolo Bonzini
2014-06-10 14:28       ` Luiz Capitulino
2014-06-03 16:39 ` [Qemu-devel] [PATCH 6/6] monitor: protect event emission Paolo Bonzini
2014-06-10 13:33   ` Luiz Capitulino
2014-06-27  9:43 ` [Qemu-devel] [PATCH 0/5] qemu-char/monitor: make monitor_puts thread safe Stefan Hajnoczi
2014-06-27 12:33   ` Luiz Capitulino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5398105D.6090701@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=famz@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).