iohandler: Use aio API
PATCH 1/1 iohandler: Use aio API
iohandler.c shares the same interface with aio, but with duplicated code. It's better to rebase iohandler, also because that aio is a more friendly interface to multi-threads.
Create a global AioContext instance and let its GSource handle the iohandler events.
Signed-off-by Fam Zheng <[email protected]>
--- include/qemu/main-loop.h | 3 +- iohandler.c | 115 +++++++---------------------------------------- main-loop.c | 5 ++- 3 files changed, 21 insertions(+), 102 deletions(-)
include/qemu/main-loop.h +1 -2
@@ -203,6 +203,7 @@ void qemu_set_fd_handler(int fd, IOHandler *fd_write, void *opaque); +GSource *iohandler_get_g_source (void );#ifdef CONFIG_POSIX /** * qemu_add_child_watch: Register a child process for reaping.
@@ -265,8 +266,6 @@ void qemu_mutex_unlock_iothread(void);/* internal interfaces */ void qemu_fd_register (int fd); -void qemu_iohandler_fill (GArray *pollfds); -void qemu_iohandler_poll (GArray *pollfds,int rc);QEMUBH *qemu_bh_new (QEMUBHFunc *cb,void *opaque);void qemu_bh_schedule_idle (QEMUBH *bh);
iohandler.c +17 -98
128 lines not on this page · raw message
main-loop.c +3 -2
@@ -161,6 +161,9 @@ int qemu_init_main_loop(Error **errp) src =aio_get_g_source (qemu_aio_context);g_source_attach (src,NULL );g_source_unref (src); + src =iohandler_get_g_source (); +g_source_attach (src,NULL ); +g_source_unref (src);return 0 ; }
@@ -487,7 +490,6 @@ int main_loop_wait(int nonblocking)#ifdef CONFIG_SLIRP slirp_pollfds_fill (gpollfds, &timeout);#endif -qemu_iohandler_fill (gpollfds);if (timeout ==UINT32_MAX ) { timeout_ns =-1 ;
@@ -500,7 +502,6 @@ int main_loop_wait(int nonblocking) &main_loop_tlg)); ret =os_host_main_loop_wait (timeout_ns); -qemu_iohandler_poll (gpollfds, ret);#ifdef CONFIG_SLIRP slirp_pollfds_poll (gpollfds, (ret <0 ));#endif
Signature · 1 line
2.4.3
Quoted 7 lines · Fam Zheng
iohandler.cshares the same interface with aio, but with duplicated code. It's better to rebase iohandler, also because that aio is a more friendly interface to multi-threads.Create a global AioContext instance and let its GSource handle the iohandler events.
Quoted 6 lines
Signed-off-by Fam Zheng <[email protected]>--- include/qemu/main-loop.h | 3 +- iohandler.c | 115 +++++++---------------------------------------- main-loop.c | 5 ++- 3 files changed, 21 insertions(+), 102 deletions(-)
Reviewed-by Stefan Hajnoczi <[email protected]>