[Spice-devel] [PATCH spice-gtk v4 1/3] emit_main_context macro: handle calls from both coroutine context and main context

Yonit Halperin yhalperi at redhat.com
Fri May 10 13:15:00 PDT 2013


---
 gtk/coroutine.h          |  1 +
 gtk/spice-channel-priv.h | 12 ++++++++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/gtk/coroutine.h b/gtk/coroutine.h
index 031a97b..a9b3a87 100644
--- a/gtk/coroutine.h
+++ b/gtk/coroutine.h
@@ -55,6 +55,7 @@ struct coroutine
 #endif
 };
 
+#define IN_MAIN_CONTEXT (coroutine_self()->caller == NULL)
 int coroutine_init(struct coroutine *co);
 
 int coroutine_release(struct coroutine *co);
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 5584662..be061c5 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -188,10 +188,14 @@ void spice_caps_set(GArray *caps, guint32 cap, const gchar *desc);
     spice_caps_set(SPICE_CHANNEL(channel)->priv->caps, cap, #cap)
 
 /* coroutine context */
-#define emit_main_context(object, event, args...)                       \
-    G_STMT_START {                                                      \
-        g_signal_emit_main_context(G_OBJECT(object), do_emit_main_context, \
-                                   event, &((struct event) { args }), G_STRLOC); \
+#define emit_main_context(object, event, args...)                                      \
+    G_STMT_START {                                                                     \
+        if (IN_MAIN_CONTEXT) {                                                         \
+            do_emit_main_context(G_OBJECT(object), event, &((struct event) { args })); \
+        } else {                                                                       \
+            g_signal_emit_main_context(G_OBJECT(object), do_emit_main_context,         \
+                                       event, &((struct event) { args }), G_STRLOC);   \
+        }                                                                              \
     } G_STMT_END
 
 gchar *spice_channel_supported_string(void);
-- 
1.8.1.4



More information about the Spice-devel mailing list