diff options
Diffstat (limited to 'chardev/char.c')
-rw-r--r-- | chardev/char.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/chardev/char.c b/chardev/char.c index 8c3765e..3e14de1 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -1084,6 +1084,24 @@ void qmp_chardev_send_break(const char *id, Error **errp) qemu_chr_be_event(chr, CHR_EVENT_BREAK); } +/* + * Add a timeout callback for the chardev (in milliseconds), return + * the GSource object created. Please use this to add timeout hook for + * chardev instead of g_timeout_add() and g_timeout_add_seconds(), to + * make sure the gcontext that the task bound to is correct. + */ +GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms, + GSourceFunc func, void *private) +{ + GSource *source = g_timeout_source_new(ms); + + assert(func); + g_source_set_callback(source, func, private, NULL); + g_source_attach(source, chr->gcontext); + + return source; +} + void qemu_chr_cleanup(void) { object_unparent(get_chardevs_root()); |