From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wudi4-0003xD-FF for qemu-devel@nongnu.org; Wed, 11 Jun 2014 04:16:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wudhy-0006cO-AT for qemu-devel@nongnu.org; Wed, 11 Jun 2014 04:16:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:19011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wudhy-0006cJ-09 for qemu-devel@nongnu.org; Wed, 11 Jun 2014 04:16:34 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5B8GXNk018912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 11 Jun 2014 04:16:33 -0400 Message-ID: <5398105D.6090701@redhat.com> Date: Wed, 11 Jun 2014 10:16:29 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1401813551-6667-1-git-send-email-pbonzini@redhat.com> <1401813551-6667-5-git-send-email-pbonzini@redhat.com> <20140611065911.GG5448@T430.nay.redhat.com> In-Reply-To: <20140611065911.GG5448@T430.nay.redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, kraxel@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, lcapitulino@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