]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
chardev/char.c: Use qemu_co_sleep_ns if in coroutine
authorLukas Straub <lukasstraub2@web.de>
Fri, 22 May 2020 07:53:52 +0000 (15:53 +0800)
committerJason Wang <jasowang@redhat.com>
Thu, 18 Jun 2020 13:05:52 +0000 (21:05 +0800)
To be able to convert compare_chr_send to a coroutine in the
next commit, use qemu_co_sleep_ns if in coroutine.

Signed-off-by: Lukas Straub <lukasstraub2@web.de>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Zhang Chen <chen.zhang@intel.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Zhang Chen <chen.zhang@intel.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
chardev/char.c

index ea06c5ff4d9b667d8caf757ed0250946326405a1..e3051295ac3774eb9c8d8a185d4a54e8d24715ae 100644 (file)
@@ -38,6 +38,7 @@
 #include "qemu/module.h"
 #include "qemu/option.h"
 #include "qemu/id.h"
+#include "qemu/coroutine.h"
 
 #include "chardev/char-mux.h"
 
@@ -119,7 +120,11 @@ static int qemu_chr_write_buffer(Chardev *s,
     retry:
         res = cc->chr_write(s, buf + *offset, len - *offset);
         if (res < 0 && errno == EAGAIN && write_all) {
-            g_usleep(100);
+            if (qemu_in_coroutine()) {
+                qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000);
+            } else {
+                g_usleep(100);
+            }
             goto retry;
         }