mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 00:33:55 -06:00
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>
This commit is contained in:
parent
938eb9e9c8
commit
2c716ba150
5 changed files with 74 additions and 46 deletions
|
@ -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());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue