Skip to content

Commit 2158fa1

Browse files
lukasstraub2jasowang
authored andcommitted
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 <[email protected]> Reviewed-by: Marc-André Lureau <[email protected]> Reviewed-by: Zhang Chen <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Zhang Chen <[email protected]> Signed-off-by: Jason Wang <[email protected]>
1 parent 5893c73 commit 2158fa1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

chardev/char.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "qemu/module.h"
3939
#include "qemu/option.h"
4040
#include "qemu/id.h"
41+
#include "qemu/coroutine.h"
4142

4243
#include "chardev/char-mux.h"
4344

@@ -119,7 +120,11 @@ static int qemu_chr_write_buffer(Chardev *s,
119120
retry:
120121
res = cc->chr_write(s, buf + *offset, len - *offset);
121122
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+
}
123128
goto retry;
124129
}
125130

0 commit comments

Comments
 (0)