From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
peterx@redhat.com,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v4 2/3] chardev: let g_idle_add() be with chardev gcontext
Date: Thu, 4 Jan 2018 22:18:34 +0800 [thread overview]
Message-ID: <20180104141835.17987-3-peterx@redhat.com> (raw)
In-Reply-To: <20180104141835.17987-1-peterx@redhat.com>
The idle task will be attached to main gcontext even if the chardev
backend is running in another gcontext. Fix the only caller by
extending the g_idle_add() logic into the more powerful
g_source_attach(). It's basically g_idle_add_full() implementation, but
with the chardev's gcontext passed in.
Signed-off-by: Peter Xu <peterx@redhat.com>
---
chardev/char-pty.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/chardev/char-pty.c b/chardev/char-pty.c
index 761ae6dec1..8248e36ab9 100644
--- a/chardev/char-pty.c
+++ b/chardev/char-pty.c
@@ -43,7 +43,7 @@ typedef struct {
/* Protected by the Chardev chr_write_lock. */
int connected;
guint timer_tag;
- guint open_tag;
+ GSource *open_source;
} PtyChardev;
#define PTY_CHARDEV(obj) OBJECT_CHECK(PtyChardev, (obj), TYPE_CHARDEV_PTY)
@@ -58,7 +58,7 @@ static gboolean pty_chr_timer(gpointer opaque)
qemu_mutex_lock(&chr->chr_write_lock);
s->timer_tag = 0;
- s->open_tag = 0;
+ s->open_source = NULL;
if (!s->connected) {
/* Next poll ... */
pty_chr_update_read_handler_locked(chr);
@@ -183,7 +183,7 @@ static gboolean qemu_chr_be_generic_open_func(gpointer opaque)
Chardev *chr = CHARDEV(opaque);
PtyChardev *s = PTY_CHARDEV(opaque);
- s->open_tag = 0;
+ s->open_source = NULL;
qemu_chr_be_event(chr, CHR_EVENT_OPENED);
return FALSE;
}
@@ -194,9 +194,10 @@ static void pty_chr_state(Chardev *chr, int connected)
PtyChardev *s = PTY_CHARDEV(chr);
if (!connected) {
- if (s->open_tag) {
- g_source_remove(s->open_tag);
- s->open_tag = 0;
+ if (s->open_source) {
+ g_source_destroy(s->open_source);
+ g_source_unref(s->open_source);
+ s->open_source = NULL;
}
remove_fd_in_watch(chr);
s->connected = 0;
@@ -210,9 +211,13 @@ static void pty_chr_state(Chardev *chr, int connected)
s->timer_tag = 0;
}
if (!s->connected) {
- g_assert(s->open_tag == 0);
+ g_assert(s->open_source == NULL);
+ s->open_source = g_idle_source_new();
s->connected = 1;
- s->open_tag = g_idle_add(qemu_chr_be_generic_open_func, chr);
+ g_source_set_callback(s->open_source,
+ qemu_chr_be_generic_open_func,
+ chr, NULL);
+ g_source_attach(s->open_source, chr->gcontext);
}
if (!chr->gsource) {
chr->gsource = io_add_watch_poll(chr, s->ioc,
--
2.14.3
next prev parent reply other threads:[~2018-01-04 14:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-04 14:18 [Qemu-devel] [PATCH v4 0/3] chardev: convert leftover glib APIs to use dedicate gcontext Peter Xu
2018-01-04 14:18 ` [Qemu-devel] [PATCH v4 1/3] chardev: use backend chr context when watch for fe Peter Xu
2018-01-04 14:18 ` Peter Xu [this message]
2018-01-04 14:18 ` [Qemu-devel] [PATCH v4 3/3] chardev: introduce qemu_chr_timeout_add_ms() Peter Xu
2018-01-04 14:30 ` [Qemu-devel] [PATCH v4 0/3] chardev: convert leftover glib APIs to use dedicate gcontext Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180104141835.17987-3-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).