$OpenBSD: patch-src_orb_GIOP_giop_c,v 1.1 2013/03/27 17:58:44 ajacoutot Exp $

From f4fd676c4864155bad10cf5a49ea5d9a0f3c1e9a Mon Sep 17 00:00:00 2001
From: Kjartan Maraas <kmaraas@gnome.org>
Date: Tue, 11 Jan 2011 22:48:59 +0000
Subject: Support for custom GMainContext from Ke Wang

--- src/orb/GIOP/giop.c.orig	Tue Feb  9 13:05:35 2010
+++ src/orb/GIOP/giop.c	Wed Mar 27 10:55:31 2013
@@ -21,6 +21,7 @@
 static int      corba_wakeup_fds[2];
 #define WAKEUP_POLL  corba_wakeup_fds [0]
 #define WAKEUP_WRITE corba_wakeup_fds [1]
+static GMainContext *giop_main_context = NULL;
 static GSource *giop_main_source = NULL;
 static GIOPThread *giop_main_thread = NULL;
 
@@ -530,19 +531,26 @@ ORBit_get_safe_tmp (void)
 }
 
 void
+giop_set_main_context (GMainContext *context)
+{
+	giop_main_context = context;
+}
+
+void
 giop_init (gboolean thread_safe, gboolean blank_wire_data)
 {
 	link_init (thread_safe);
 
 	if (giop_thread_safe ()) {
 		GIOPThread *tdata;
+		if (!giop_main_context)
+			giop_main_context = g_main_context_default();
 
 		/* We need a destructor to clean up if giopthreads are used
 		 * outside of ORBit controlled threads */
 		giop_tdata_private = g_private_new ((GDestroyNotify)giop_thread_free);
 
-		giop_main_thread = tdata = giop_thread_new (
-			g_main_context_default ()); /* main thread */
+		giop_main_thread = tdata = giop_thread_new (giop_main_context); /* main thread */
 
 		if (link_pipe (corba_wakeup_fds) < 0) /* cf. g_main_context_init_pipe */
 			g_error ("Can't create CORBA main-thread wakeup pipe");
@@ -556,7 +564,7 @@ giop_init (gboolean thread_safe, gboolean blank_wire_d
 		fcntl (WAKEUP_WRITE, F_SETFL, O_NONBLOCK);
 #endif
 		giop_main_source = link_source_create_watch (
-			g_main_context_default (), WAKEUP_POLL,
+			giop_main_context, WAKEUP_POLL,
 			NULL, (G_IO_IN | G_IO_PRI),
 			giop_mainloop_handle_input, NULL);
 		
