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: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe
Date: Wed, 11 Jun 2014 10:16:29 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

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 via email to

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