From 34c1dc50ae3e33a7eb384c98f532156ecdfa34de Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Sat, 17 Apr 2021 16:29:03 +0900 Subject: [PATCH] iodev: Add iodev_handle_events() and iodev_console_flush() Signed-off-by: Hector Martin --- src/iodev.c | 16 ++++++++++++++++ src/iodev.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/src/iodev.c b/src/iodev.c index 9e421d07..a40604dd 100644 --- a/src/iodev.c +++ b/src/iodev.c @@ -136,3 +136,19 @@ void iodev_console_write(const void *buf, size_t length) in_iodev--; } + +void iodev_handle_events(iodev_id_t id) +{ + if (in_iodev) + return; + + in_iodev++; + + if (iodevs[id]->ops->handle_events) + iodevs[id]->ops->handle_events(iodevs[id]->opaque); + + in_iodev--; + + if (iodev_can_write(id)) + iodev_console_flush(); +} diff --git a/src/iodev.h b/src/iodev.h index 532e2cc0..c7e105fb 100644 --- a/src/iodev.h +++ b/src/iodev.h @@ -18,6 +18,7 @@ struct iodev_ops { bool (*can_write)(void *opaque); ssize_t (*read)(void *opaque, void *buf, size_t length); ssize_t (*write)(void *opaque, const void *buf, size_t length); + void (*handle_events)(void *opaque); }; struct iodev { @@ -33,8 +34,13 @@ bool iodev_can_read(iodev_id_t id); bool iodev_can_write(iodev_id_t id); ssize_t iodev_read(iodev_id_t id, void *buf, size_t length); ssize_t iodev_write(iodev_id_t id, const void *buf, size_t length); +void iodev_handle_events(iodev_id_t id); void iodev_console_write(const void *buf, size_t length); +static inline void iodev_console_flush(void) +{ + iodev_console_write(NULL, 0); +} static inline void iodev_set_usage(iodev_id_t id, iodev_usage_t usage) {