qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

chardev/char.c: Use qemu_co_sleep_ns if in coroutine

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>

authored by

Lukas Straub and committed by
Jason Wang
2158fa1b 5893c738

+6 -1
+6 -1
chardev/char.c
··· 38 38 #include "qemu/module.h" 39 39 #include "qemu/option.h" 40 40 #include "qemu/id.h" 41 + #include "qemu/coroutine.h" 41 42 42 43 #include "chardev/char-mux.h" 43 44 ··· 119 120 retry: 120 121 res = cc->chr_write(s, buf + *offset, len - *offset); 121 122 if (res < 0 && errno == EAGAIN && write_all) { 122 - g_usleep(100); 123 + if (qemu_in_coroutine()) { 124 + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000); 125 + } else { 126 + g_usleep(100); 127 + } 123 128 goto retry; 124 129 } 125 130