qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default())
@ 2016-06-20  8:23 Zhang Chen
  2016-06-20  8:52 ` Paolo Bonzini
  2016-06-20 16:45 ` Eric Blake
  0 siblings, 2 replies; 5+ messages in thread
From: Zhang Chen @ 2016-06-20  8:23 UTC (permalink / raw)
  To: qemu devel, Daniel P . Berrange, Paolo Bonzini
  Cc: Jason Wang, Zhang Chen, Li Zhijian, Wen Congyang, eddie . dong

We want to poll and handle chardev in another thread
other than main loop. But qemu_chr_add_handlers() can only
work for global default context other than thread default context.
So we use g_souce_attach(xx, g_main_context_get_thread_default())
replace g_source_attach(xx, NULL) to attach g_source.
Comments form jason.

Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 io/channel.c | 2 +-
 qemu-char.c  | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/io/channel.c b/io/channel.c
index 692eb17..cd25677 100644
--- a/io/channel.c
+++ b/io/channel.c
@@ -146,7 +146,7 @@ guint qio_channel_add_watch(QIOChannel *ioc,
 
     g_source_set_callback(source, (GSourceFunc)func, user_data, notify);
 
-    id = g_source_attach(source, NULL);
+    id = g_source_attach(source, g_main_context_get_thread_default());
     g_source_unref(source);
 
     return id;
diff --git a/qemu-char.c b/qemu-char.c
index 84f49ac..4340457 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -859,7 +859,7 @@ static gboolean io_watch_poll_prepare(GSource *source, gint *timeout_)
         iwp->src = qio_channel_create_watch(
             iwp->ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL);
         g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL);
-        g_source_attach(iwp->src, NULL);
+        g_source_attach(iwp->src, g_main_context_get_thread_default());
     } else {
         g_source_destroy(iwp->src);
         g_source_unref(iwp->src);
@@ -918,7 +918,7 @@ static guint io_add_watch_poll(QIOChannel *ioc,
     iwp->fd_read = (GSourceFunc) fd_read;
     iwp->src = NULL;
 
-    tag = g_source_attach(&iwp->parent, NULL);
+    tag = g_source_attach(&iwp->parent, g_main_context_get_thread_default());
     g_source_unref(&iwp->parent);
     return tag;
 }
@@ -3982,7 +3982,7 @@ int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
     }
 
     g_source_set_callback(src, (GSourceFunc)func, user_data, NULL);
-    tag = g_source_attach(src, NULL);
+    tag = g_source_attach(src, g_main_context_get_thread_default());
     g_source_unref(src);
 
     return tag;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default())
  2016-06-20  8:23 [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default()) Zhang Chen
@ 2016-06-20  8:52 ` Paolo Bonzini
  2016-06-20  9:20   ` Zhang Chen
  2016-06-20 16:45 ` Eric Blake
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2016-06-20  8:52 UTC (permalink / raw)
  To: Zhang Chen, qemu devel, Daniel P . Berrange
  Cc: eddie . dong, Jason Wang, Li Zhijian



On 20/06/2016 10:23, Zhang Chen wrote:
> We want to poll and handle chardev in another thread
> other than main loop.

Can you explain this better?

Paolo

> But qemu_chr_add_handlers() can only
> work for global default context other than thread default context.
> So we use g_souce_attach(xx, g_main_context_get_thread_default())
> replace g_source_attach(xx, NULL) to attach g_source.
> Comments form jason.
> 
> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default())
  2016-06-20  8:52 ` Paolo Bonzini
@ 2016-06-20  9:20   ` Zhang Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Zhang Chen @ 2016-06-20  9:20 UTC (permalink / raw)
  To: Paolo Bonzini, qemu devel, Daniel P . Berrange
  Cc: eddie . dong, Jason Wang, Li Zhijian



On 06/20/2016 04:52 PM, Paolo Bonzini wrote:
>
> On 20/06/2016 10:23, Zhang Chen wrote:
>> We want to poll and handle chardev in another thread
>> other than main loop.
> Can you explain this better?

For example, we use this in codes:

+    qemu_chr_add_handlers(s->chr_sec_in, compare_chr_can_read,
+                          compare_sec_chr_in, NULL, s);

when data come to s->chr_sec_in ,we want to make
compare_sec_chr_in() run in another thread rather
than main loop.


Thanks
Zhang Chen

>
> Paolo
>
>> But qemu_chr_add_handlers() can only
>> work for global default context other than thread default context.
>> So we use g_souce_attach(xx, g_main_context_get_thread_default())
>> replace g_source_attach(xx, NULL) to attach g_source.
>> Comments form jason.
>>
>> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>
>

-- 
Thanks
zhangchen

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default())
  2016-06-20  8:23 [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default()) Zhang Chen
  2016-06-20  8:52 ` Paolo Bonzini
@ 2016-06-20 16:45 ` Eric Blake
  2016-06-21  1:32   ` Zhang Chen
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Blake @ 2016-06-20 16:45 UTC (permalink / raw)
  To: Zhang Chen, qemu devel, Daniel P . Berrange, Paolo Bonzini
  Cc: eddie . dong, Jason Wang, Li Zhijian

[-- Attachment #1: Type: text/plain, Size: 906 bytes --]

On 06/20/2016 02:23 AM, Zhang Chen wrote:

Subject line is too long, missing a 'topic:' prefix, and has a typo
(souce).  Suggest:

qemu-char: Fix context for g_source_attach()

> We want to poll and handle chardev in another thread
> other than main loop. But qemu_chr_add_handlers() can only
> work for global default context other than thread default context.
> So we use g_souce_attach(xx, g_main_context_get_thread_default())

s/souce/source/

> replace g_source_attach(xx, NULL) to attach g_source.
> Comments form jason.

s/form/from/ ?

> 
> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  io/channel.c | 2 +-
>  qemu-char.c  | 6 +++---
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default())
  2016-06-20 16:45 ` Eric Blake
@ 2016-06-21  1:32   ` Zhang Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Zhang Chen @ 2016-06-21  1:32 UTC (permalink / raw)
  To: Eric Blake, qemu devel, Daniel P . Berrange, Paolo Bonzini
  Cc: eddie . dong, Jason Wang, Li Zhijian



On 06/21/2016 12:45 AM, Eric Blake wrote:
> On 06/20/2016 02:23 AM, Zhang Chen wrote:
>
> Subject line is too long, missing a 'topic:' prefix, and has a typo
> (souce).  Suggest:
>
> qemu-char: Fix context for g_source_attach()

OK~~ I will fix it in next version.

>
>> We want to poll and handle chardev in another thread
>> other than main loop. But qemu_chr_add_handlers() can only
>> work for global default context other than thread default context.
>> So we use g_souce_attach(xx, g_main_context_get_thread_default())
> s/souce/source/

will fix...

>
>> replace g_source_attach(xx, NULL) to attach g_source.
>> Comments form jason.
> s/form/from/ ?

Yes...will fix in next version.

Thanks
Zhang Chen

>
>> Signed-off-by: Zhang Chen <zhangchen.fnst@cn.fujitsu.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>> ---
>>   io/channel.c | 2 +-
>>   qemu-char.c  | 6 +++---
>>   2 files changed, 4 insertions(+), 4 deletions(-)
>>

-- 
Thanks
zhangchen

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-21  1:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-20  8:23 [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default()) Zhang Chen
2016-06-20  8:52 ` Paolo Bonzini
2016-06-20  9:20   ` Zhang Chen
2016-06-20 16:45 ` Eric Blake
2016-06-21  1:32   ` Zhang Chen

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).