---
 Headers/GNUstepBase/GSObjCRuntime.h |  8 ++++++++
 Source/Additions/GSObjCRuntime.m    | 28 ++++++++++++++++++++++++++++
 Source/NSThread.m                   | 24 ++----------------------
 3 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/Headers/GNUstepBase/GSObjCRuntime.h b/Headers/GNUstepBase/GSObjCRuntime.h
index 0b5057c..91f7f8e 100644
--- a/Headers/GNUstepBase/GSObjCRuntime.h
+++ b/Headers/GNUstepBase/GSObjCRuntime.h
@@ -468,6 +468,14 @@ GSObjCDirectSubclassesOfClass(Class cls);
 GS_EXPORT void
 GSClassSwizzle(id instance, Class newClass);
 
+#if GS_WITH_GC || __OBJC_GC__
+/** Function to prepare threads for garbage allocator.
+ * This is used by libdispatch to get its worker threads ready for GC.
+ */
+GS_EXPORT void
+GSRegisterThreadWithGC(void);
+#endif
+
 #if GS_API_VERSION(GS_API_ANY,011500)
 
 GS_EXPORT const char *
diff --git a/Source/Additions/GSObjCRuntime.m b/Source/Additions/GSObjCRuntime.m
index 59b6d56..5945caa 100644
--- a/Source/Additions/GSObjCRuntime.m
+++ b/Source/Additions/GSObjCRuntime.m
@@ -2058,6 +2058,34 @@ GSFinalize(void* object, void* data)
 }
 
 # endif	/* GS_WITH_GC */
+
+# if GS_WITH_GC || __OBJC_GC__
+void
+GSRegisterThreadWithGC(void)
+{
+#if __OBJC_GC__
+  objc_registerThreadWithCollector();
+#endif
+#if	GS_WITH_GC && defined(HAVE_GC_REGISTER_MY_THREAD)
+  struct GC_stack_base        base;
+
+  if (GC_get_stack_base(&base) == GC_SUCCESS)
+    {
+      int     result;
+
+      result = GC_register_my_thread(&base);
+      if (result != GC_SUCCESS && result != GC_DUPLICATE)
+        {
+          fprintf(stderr, "Argh ... no thread support in garbage collection library\n");
+        }
+    }
+  else
+    {
+      fprintf(stderr, "Unable to determine stack base to register new thread for garbage collection\n");
+    }
+#endif
+}
+# endif /* GS_WITH_GC || __OBJC_GC__ */
 #endif	/* defined(GNUSTEP_BASE_LIBRARY) */
 
 void
diff --git a/Source/NSThread.m b/Source/NSThread.m
index 05fed4c..c3447bf 100644
--- a/Source/NSThread.m
+++ b/Source/NSThread.m
@@ -771,28 +771,8 @@ static void *nsthreadLauncher(void* thread)
 {
     NSThread *t = (NSThread*)thread;
     setThreadForCurrentThread(t);
-#if __OBJC_GC__
-	objc_registerThreadWithCollector();
-#endif
-#if	GS_WITH_GC && defined(HAVE_GC_REGISTER_MY_THREAD)
-  {
-    struct GC_stack_base	base;
-
-    if (GC_get_stack_base(&base) == GC_SUCCESS)
-      {
-	int	result;
-
-	result = GC_register_my_thread(&base);
-	if (result != GC_SUCCESS && result != GC_DUPLICATE)
-	  {
-	    fprintf(stderr, "Argh ... no thread support in garbage collection library\n");
-	  }
-      }
-    else
-      {
-	fprintf(stderr, "Unable to determine stack base to register new thread for garbage collection\n");
-      }
-  }
+#if GS_WITH_GC || __OBJC_GC__
+    GSRegisterThreadWithGC();
 #endif
 
   /*
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to