qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH ] yield_until_fd_readable: make it work with any AioContect


From: Dietmar Maurer
Subject: [PATCH ] yield_until_fd_readable: make it work with any AioContect
Date: Sun, 20 Oct 2019 15:56:28 +0200

Simply use qemu_get_current_aio_context().

Signed-off-by: Dietmar Maurer <address@hidden>
---
 util/qemu-coroutine-io.c | 20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/util/qemu-coroutine-io.c b/util/qemu-coroutine-io.c
index 44a8969a69..2938c5420c 100644
--- a/util/qemu-coroutine-io.c
+++ b/util/qemu-coroutine-io.c
@@ -66,25 +66,11 @@ qemu_co_send_recv(int sockfd, void *buf, size_t bytes, bool 
do_send)
     return qemu_co_sendv_recvv(sockfd, &iov, 1, 0, bytes, do_send);
 }
 
-typedef struct {
-    Coroutine *co;
-    int fd;
-} FDYieldUntilData;
-
-static void fd_coroutine_enter(void *opaque)
-{
-    FDYieldUntilData *data = opaque;
-    qemu_set_fd_handler(data->fd, NULL, NULL, NULL);
-    qemu_coroutine_enter(data->co);
-}
-
 void coroutine_fn yield_until_fd_readable(int fd)
 {
-    FDYieldUntilData data;
-
     assert(qemu_in_coroutine());
-    data.co = qemu_coroutine_self();
-    data.fd = fd;
-    qemu_set_fd_handler(fd, fd_coroutine_enter, NULL, &data);
+    AioContext *ctx = qemu_get_current_aio_context();
+    aio_set_fd_handler(ctx, fd, false, NULL, (void (*)(void 
*))qemu_coroutine_enter, NULL, qemu_coroutine_self());
     qemu_coroutine_yield();
+    aio_set_fd_handler(ctx, fd, false, NULL, NULL, NULL, NULL);
 }
-- 
2.20.1




reply via email to

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