This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Add objc_thread_add and objc_thread_remove to libobjc


Hi

here are two functions which can be used to have Objective-C threads
cooperate with threads started from alien environments (eg, to allow
Objective-C calls being made from arbitrary Java threads without causing
thread problems to the objc runtime).  This functionality is not covered
by existing libobjc thread code as all code there requires you to start
and stop your threads using libobjc - you can't access the runtime from a
thread started by java for example.  These two functions fix this problem. 

In GNUstep we already use these two functions in the base library (and
they are used extensively to interface the thread system with Java so they
have been tested), they have been there for quite a while now, only it
makes much more sense to define/implement them in libobjc rather than in
the gnustep base library, as they really belong to libobjc.  Moreover, I
have been told (by Adam Fedor) that having these functions in gnustep-base
makes linking on windows more difficult, because the functions access
private internals of the objc runtime which are not exported on windows,
so I'd be glad if we could simply move the functions to libobjc where they
belong. 

I'd appreciate if they could be committed to 3.0 as well so that we kill
this bug/problem of linking on windows.  I understand it's sort of an
exception but it's extremely clear they don't introduce new bugs or break
any existing code.

Index: libobjc/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/ChangeLog,v
retrieving revision 1.53
diff -u -r1.53 ChangeLog
--- ChangeLog	2001/02/28 17:17:09	1.53
+++ ChangeLog	2001/03/10 11:54:46
@@ -1,3 +1,9 @@
+Sat Mar 10 15:05:26 2001  Nicola Pero  <n.pero@mi.flashnet.it>
+
+	* thr.c (objc_thread_add), (objc_thread_remove): New functions.
+	* objc/thr.h: Declare the new functions.
+	* libobjc.def: Added the new functions.
+
 2001-02-28  Ovidiu Predescu  <ovidiu@cup.hp.com>
 
 	* objc-features.texi: Document the @compatibility_alias compiler
Index: libobjc/libobjc.def
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/libobjc.def,v
retrieving revision 1.2
diff -u -r1.2 libobjc.def
--- libobjc.def	1999/09/04 15:09:19	1.2
+++ libobjc.def	2001/03/10 11:54:46
@@ -45,6 +45,8 @@
 objc_thread_set_data
 objc_thread_set_priority
 objc_thread_yield
+objc_thread_add
+objc_thread_remove
 __objc_class_name_Object
 __objc_class_name_Protocol
 __objc_class_name_NXConstantString
Index: libobjc/thr.c
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/thr.c,v
retrieving revision 1.2
diff -u -r1.2 thr.c
--- thr.c	1999/09/04 15:09:20	1.2
+++ thr.c	2001/03/10 11:54:53
@@ -531,4 +531,33 @@
   return __objc_condition_signal(condition);
 }
 
+/* Make the objc thread system aware that a thread which is managed
+   (started, stopped) by external code could access objc facilities
+   from now on.  This is used when you are interfacing with some
+   external non-objc-based environment/system - you must call
+   objc_thread_add() before an alien thread makes any calls to
+   Objective-C.  Do not cause the _objc_became_multi_threaded hook to
+   be executed. */
+void 
+objc_thread_add(void)
+{
+  objc_mutex_lock(__objc_runtime_mutex);
+  __objc_is_multi_threaded = 1;
+  __objc_runtime_threads_alive++;
+  objc_mutex_unlock(__objc_runtime_mutex);  
+}
+
+/* Make the objc thread system aware that a thread managed (started,
+   stopped) by some external code will no longer access objc and thus
+   can be forgotten by the objc thread system.  Call
+   objc_thread_remove() when your alien thread is done with making calls
+   to Objective-C. */
+void
+objc_thread_remove(void)
+{
+  objc_mutex_lock(__objc_runtime_mutex);
+  __objc_runtime_threads_alive--;
+  objc_mutex_unlock(__objc_runtime_mutex);  
+}
+
 /* End of File */
Index: libobjc/objc/thr.h
===================================================================
RCS file: /cvs/gcc/gcc/libobjc/objc/thr.h,v
retrieving revision 1.2
diff -u -r1.2 thr.h
--- thr.h	1999/09/04 15:09:20	1.2
+++ thr.h	2001/03/10 11:54:54
@@ -96,6 +96,8 @@
 void * objc_thread_get_data(void);
 int objc_thread_set_data(void *value);
 objc_thread_t objc_thread_id(void);
+void objc_thread_add(void);
+void objc_thread_remove(void);
 
 /*
   Use this to set the hook function that will be called when the 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]