diff options
author | Peter Xu <peterx@redhat.com> | 2018-01-04 22:18:35 +0800 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2018-01-12 13:22:02 +0100 |
commit | 2c716ba1506769c9be2caa02f0f6d6e7c00f4304 (patch) | |
tree | 233189ca8b845f83871b104d50dcdedcb264484c /chardev/char.c | |
parent | 938eb9e9c83d34d90cac6ec5c5388e7998840e4e (diff) |
chardev: introduce qemu_chr_timeout_add_ms()
It's a replacement of g_timeout_add[_seconds]() for chardevs. Chardevs
now can have dedicated gcontext, we should always bind chardev tasks
onto those gcontext rather than the default main context. Since there
are quite a few of g_timeout_add[_seconds]() callers, a new function
qemu_chr_timeout_add_ms() is introduced.
One thing to mention is that, terminal3270 is still always running on
main gcontext. However let's convert that as well since it's still part
of chardev codes and in case one day we'll miss that when we move it out
of main gcontext too.
Also, convert all the timers from GSource tags into GSource pointers.
Gsource tag IDs and g_source_remove()s can only work with default
gcontext, while now these GSources can logically be attached to other
contexts. So let's use explicit g_source_destroy() plus another
g_source_unref() to remove a timer.
Note: when in the timer handler, we don't need the g_source_destroy()
any more since that'll be done automatically if the timer handler
returns false (and that's what all the current handlers do).
Yet another note: in pty_chr_rearm_timer() we take special care for
ms=1000. This patch merged the two cases into one.
Signed-off-by: Peter Xu <peterx@redhat.com>
Message-Id: <20180104141835.17987-4-peterx@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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 8c3765ee99..3e14de1920 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()); |