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 /hw/char | |
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 'hw/char')
-rw-r--r-- | hw/char/terminal3270.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index a109ce5987..e9c45e55b1 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -31,7 +31,7 @@ typedef struct Terminal3270 { uint8_t outv[OUTPUT_BUFFER_SIZE]; int in_len; bool handshake_done; - guint timer_tag; + GSource *timer_src; } Terminal3270; #define TYPE_TERMINAL_3270 "x-terminal3270" @@ -45,6 +45,15 @@ static int terminal_can_read(void *opaque) return INPUT_BUFFER_SIZE - t->in_len; } +static void terminal_timer_cancel(Terminal3270 *t) +{ + if (t->timer_src) { + g_source_destroy(t->timer_src); + g_source_unref(t->timer_src); + t->timer_src = NULL; + } +} + /* * Protocol handshake done, * signal guest by an unsolicited DE irq. @@ -90,12 +99,9 @@ static void terminal_read(void *opaque, const uint8_t *buf, int size) assert(size <= (INPUT_BUFFER_SIZE - t->in_len)); - if (t->timer_tag) { - g_source_remove(t->timer_tag); - t->timer_tag = 0; - } - t->timer_tag = g_timeout_add_seconds(600, send_timing_mark_cb, t); - + terminal_timer_cancel(t); + t->timer_src = qemu_chr_timeout_add_ms(t->chr.chr, 600 * 1000, + send_timing_mark_cb, t); memcpy(&t->inv[t->in_len], buf, size); t->in_len += size; if (t->in_len < 2) { @@ -145,10 +151,7 @@ static void chr_event(void *opaque, int event) /* Ensure the initial status correct, always reset them. */ t->in_len = 0; t->handshake_done = false; - if (t->timer_tag) { - g_source_remove(t->timer_tag); - t->timer_tag = 0; - } + terminal_timer_cancel(t); switch (event) { case CHR_EVENT_OPENED: @@ -157,7 +160,8 @@ static void chr_event(void *opaque, int event) * char-socket.c. Once qemu receives the terminal-type of the * client, mark handshake done and trigger everything rolling again. */ - t->timer_tag = g_timeout_add_seconds(600, send_timing_mark_cb, t); + t->timer_src = qemu_chr_timeout_add_ms(t->chr.chr, 600 * 1000, + send_timing_mark_cb, t); break; case CHR_EVENT_CLOSED: sch->curr_status.scsw.dstat = SCSW_DSTAT_DEVICE_END; |