[evolution-patches] ORBit2 ON_CONTEXT policy patch



I've been trying to get the evolution-sharp stuff working, and for some
reason the threading interactions between mono and ebook are worse than
those between evolution and ebook, so much so that I was getting async X
reply errors.

This patch implements the ON_CONTEXT POA threading policy.  I'm not sure
I have everything completely right, but from the name it seems like it
would dispatch via idle calls on a specific GMainContext.  This means
that the *only* things seen by the mainloop ebook creates in a separate
thread are the corba calls from e-d-s.

There are some holes yet (where would I unref the context, for
instance?  probably the same place i'd destroy pending idle functions,
which are currently a FIXME.)

I've built ORBit2 with this patch and verified that it (along with some
tiny changes to ebook to make use of the policy) doesn't break evolution
1.5, and also verified that it fixes the evolution-sharp async reply
errors.

Chris
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/ORBit2/ChangeLog,v
retrieving revision 1.629
diff -u -r1.629 ChangeLog
--- ChangeLog	6 Feb 2004 11:31:59 -0000	1.629
+++ ChangeLog	7 Feb 2004 05:58:41 -0000
@@ -1,3 +1,19 @@
+2004-02-06  Chris Toshok  <toshok ximian com>
+
+	* src/orb/poa/poa.c (push_request_idle_for_context): new function,
+	dispatch a request in an idle handler on a specific GMainContext.
+	(ORBit_POA_handle_request): implement
+	ORBIT_THREAD_HINT_ON_CONTEXT.
+	(ORBit_poa_allow_cross_thread_call): add ON_CONTEXT where the
+	other idle poa policies are.
+
+	* src/orb/poa/object-adaptor.c
+	(ORBit_ObjectAdaptor_set_thread_hintv): add some code to extract
+	the GMainContext out of the arg list in the ON_CONTEXT case.
+
+	* include/orbit/poa/orbit-adaptor.h (ORBit_ObjectAdaptor_type):
+	add context slot.
+
 2004-02-06  Michael Meeks  <michael ximian com>
 
 	* src/orb/orb-core/Makefile.am (IDL_DIR): set
Index: include/orbit/poa/orbit-adaptor.h
===================================================================
RCS file: /cvs/gnome/ORBit2/include/orbit/poa/orbit-adaptor.h,v
retrieving revision 1.15
diff -u -r1.15 orbit-adaptor.h
--- include/orbit/poa/orbit-adaptor.h	2 Oct 2003 16:11:05 -0000	1.15
+++ include/orbit/poa/orbit-adaptor.h	7 Feb 2004 05:58:41 -0000
@@ -122,6 +122,8 @@
 	ORBit_AdaptorKey               adaptor_key;
 
 	ORBitThreadHint                thread_hint;
+
+	GMainContext                  *context;
 };
 
 int ORBit_adaptor_setup (ORBit_ObjectAdaptor adaptor, CORBA_ORB orb);
Index: src/orb/poa/orbit-adaptor.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/poa/orbit-adaptor.c,v
retrieving revision 1.25
diff -u -r1.25 orbit-adaptor.c
--- src/orb/poa/orbit-adaptor.c	14 Jan 2004 15:51:01 -0000	1.25
+++ src/orb/poa/orbit-adaptor.c	7 Feb 2004 05:58:41 -0000
@@ -16,7 +16,7 @@
 {
 	g_return_if_fail (adaptor != NULL);
 	g_return_if_fail (thread_hint >= ORBIT_THREAD_HINT_NONE &&
-			  thread_hint <= ORBIT_THREAD_HINT_ALL_AT_IDLE);
+			  thread_hint <= ORBIT_THREAD_HINT_ON_CONTEXT);
 
 	adaptor->thread_hint = thread_hint;
 	switch (thread_hint) {
@@ -33,6 +33,16 @@
 	case ORBIT_THREAD_HINT_ALL_AT_IDLE:
 		break;
 	}
+
+	if (thread_hint == ORBIT_THREAD_HINT_ON_CONTEXT) {
+		adaptor->context = va_arg (args, GMainContext*);
+		if (adaptor->context)
+			g_main_context_ref (adaptor->context);
+		else {
+			g_warning ("POA thread policy of ORBIT_THREAD_HINT_ON_CONTEXT chosen, but NULL context supplied.  will dispatch to default context.");
+		}
+		  
+	}
 }
 
 void
Index: src/orb/poa/poa.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/orb/poa/poa.c,v
retrieving revision 1.116
diff -u -r1.116 poa.c
--- src/orb/poa/poa.c	14 Jan 2004 15:51:01 -0000	1.116
+++ src/orb/poa/poa.c	7 Feb 2004 05:58:42 -0000
@@ -1488,6 +1488,30 @@
 	*recv_buffer = NULL;
 }
 
+static void
+push_request_idle_for_context (ORBit_POAObject  *pobj,
+			       GIOPRecvBuffer  **recv_buffer)
+{
+	ORBit_ObjectAdaptor adaptor = (ORBit_ObjectAdaptor) (*pobj)->poa;
+	PoaIdleClosure *pcl = g_new (PoaIdleClosure, 1);
+	GSource *source;
+
+	pcl->pobj = *pobj;
+	pcl->recv_buffer = *recv_buffer;
+
+	source = g_idle_source_new ();
+	g_source_set_callback (source, poa_invoke_at_idle, pcl, NULL);
+
+	/* FIXME: track pending idle impls
+	 * for cleanup at shutdown ... */
+	g_source_attach (source, adaptor->context);
+	g_source_unref (source);
+
+	
+	*pobj = NULL;
+	*recv_buffer = NULL;
+}
+
 static gboolean
 poa_recv_is_oneway (ORBit_POAObject pobj,
 		    GIOPRecvBuffer *recv_buffer)
@@ -1592,6 +1616,10 @@
 					push_request_idle (&pobj, &recv_buffer);
 					break;
 
+				case ORBIT_THREAD_HINT_ON_CONTEXT:
+					push_request_idle_for_context (&pobj, &recv_buffer);
+					break;
+
 				case ORBIT_THREAD_HINT_NONE:
 					if (giop_thread_io ())
 						push_request_T (giop_thread_get_main (),
@@ -2506,6 +2534,7 @@
 			
 		case ORBIT_THREAD_HINT_ONEWAY_AT_IDLE:
 		case ORBIT_THREAD_HINT_ALL_AT_IDLE:
+		case ORBIT_THREAD_HINT_ON_CONTEXT:
 		case ORBIT_THREAD_HINT_NONE:
 			break;
 		}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]