iodev: Add iodev_handle_events() and iodev_console_flush()

Signed-off-by: Hector Martin <marcan@marcan.st>
This commit is contained in:
Hector Martin 2021-04-17 16:29:03 +09:00
parent d3957cc89d
commit 34c1dc50ae
2 changed files with 22 additions and 0 deletions

View file

@ -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();
}

View file

@ -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)
{