In class/Microsoft.Build.Engine/Microsoft.Build.BuildEngine:
[mono.git] / libgc / pthread_support.c
index e2fef71968d8ede640ccf7b900fb6dc7c5a63882..46a5f1f469fee38c061a4d85f9ecedb7ab2a28d1 100644 (file)
@@ -67,8 +67,8 @@
 # endif
 
 # if (defined(GC_DGUX386_THREADS) || defined(GC_OSF1_THREADS) || \
-      defined(GC_DARWIN_THREADS) || defined(GC_AIX_THREADS)) \
-      && !defined(USE_PTHREAD_SPECIFIC)
+      defined(GC_DARWIN_THREADS) || defined(GC_AIX_THREADS)) || \
+      defined(GC_NETBSD_THREADS) && !defined(USE_PTHREAD_SPECIFIC)
 #   define USE_PTHREAD_SPECIFIC
 # endif
 
       typedef pthread_key_t GC_key_t;
 #   endif
 #   if defined(USE_COMPILER_TLS)
+/* Note sles9 gcc on powerpc gets confused by the define to set GC_thread_tls and pthread_setspecific
+ * so we actually use a static inline function decalred below that is equivalent to:
+ *   define GC_setspecific(key, v) (GC_thread_tls = (v), pthread_setspecific ((key), (v)))
+ */
 #     define GC_getspecific(x) (GC_thread_tls)
-#     define GC_setspecific(key, v) (GC_thread_tls = (v), pthread_setspecific ((key), (v)))
 #     define GC_key_create pthread_key_create
       typedef pthread_key_t GC_key_t;
 #   endif
 # include <sys/sysctl.h>
 #endif /* GC_DARWIN_THREADS */
 
+#if defined(GC_NETBSD_THREADS)
+# include <sys/param.h>
+# include <sys/sysctl.h>
+#endif
+
 
 
 #if defined(GC_DGUX386_THREADS)
@@ -186,7 +194,19 @@ static
 GC_key_t GC_thread_key;
 
 #ifdef USE_COMPILER_TLS
-static __thread MONO_TLS_FAST void* GC_thread_tls;
+__thread MONO_TLS_FAST void* GC_thread_tls;
+
+/*
+ * gcc errors out with /tmp/ccdPMFuq.s:2994: Error: symbol `.LTLS4' is already defined
+ * if the inline is added on powerpc
+ */
+#if !defined(__ppc__) && !defined(__powerpc__)
+inline
+#endif
+static int GC_setspecific (GC_key_t key, void *value) {
+       GC_thread_tls = value;
+       return pthread_setspecific (key, value);
+}
 #endif
 
 static GC_bool keys_initialized;
@@ -700,6 +720,11 @@ void GC_delete_thread(pthread_t id)
     if (gc_thread_vtable && gc_thread_vtable->thread_exited)
        gc_thread_vtable->thread_exited (id, &p->stop_info.stack_ptr);
 #endif
+       
+#ifdef GC_DARWIN_THREADS
+       mach_port_deallocate(mach_task_self(), p->stop_info.mach_thread);
+#endif
+       
     GC_INTERNAL_FREE(p);
 }
 
@@ -722,6 +747,11 @@ void GC_delete_gc_thread(pthread_t id, GC_thread gc_id)
     } else {
         prev -> next = p -> next;
     }
+       
+#ifdef GC_DARWIN_THREADS
+       mach_port_deallocate(mach_task_self(), p->stop_info.mach_thread);
+#endif
+       
     GC_INTERNAL_FREE(p);
 }
 
@@ -980,7 +1010,11 @@ void GC_thr_init()
       t -> flags = DETACHED | MAIN_THREAD;
 #ifdef MONO_DEBUGGER_SUPPORTED
       if (gc_thread_vtable && gc_thread_vtable->thread_created)
-        gc_thread_vtable->thread_created (pthread_self (), &t->stop_info.stack_ptr);
+#     ifdef GC_DARWIN_THREADS
+        gc_thread_vtable->thread_created (mach_thread_self (), &t->stop_info.stack_ptr);
+#     else
+         gc_thread_vtable->thread_created (pthread_self (), &t->stop_info.stack_ptr);
+#     endif
 #endif
 
     GC_stop_init();
@@ -1003,7 +1037,7 @@ void GC_thr_init()
          GC_nprocs = sysconf(_SC_NPROC_ONLN);
          if (GC_nprocs <= 0) GC_nprocs = 1;
 #       endif
-#       if defined(GC_DARWIN_THREADS) || defined(GC_FREEBSD_THREADS)
+#       if defined(GC_DARWIN_THREADS) || defined(GC_FREEBSD_THREADS) || defined(GC_NETBSD_THREADS)
          int ncpus = 1;
          size_t len = sizeof(ncpus);
          sysctl((int[2]) {CTL_HW, HW_NCPU}, 2, &ncpus, &len, NULL, 0);
@@ -1170,6 +1204,11 @@ void GC_thread_exit_proc(void *arg)
     me = GC_lookup_thread(pthread_self());
     GC_destroy_thread_local(me);
     if (me -> flags & DETACHED) {
+# ifdef THREAD_LOCAL_ALLOC
+               /* NULL out the tls key to prevent the dtor function from being called */
+               if (0 != GC_setspecific(GC_thread_key, NULL))
+                       ABORT("Failed to set thread specific allocation pointers");
+#endif
        GC_delete_thread(pthread_self());
     } else {
        me -> flags |= FINISHED;
@@ -1289,7 +1328,11 @@ void * GC_start_routine_head(void * arg, void *base_addr,
 #   endif /* IA64 */
 #ifdef MONO_DEBUGGER_SUPPORTED
     if (gc_thread_vtable && gc_thread_vtable->thread_created)
-       gc_thread_vtable->thread_created (my_pthread, &me->stop_info.stack_ptr);
+#      ifdef GC_DARWIN_THREADS
+       gc_thread_vtable->thread_created (mach_thread_self(), &me->stop_info.stack_ptr);
+#      else
+       gc_thread_vtable->thread_created (my_pthread, &me->stop_info.stack_ptr);
+#      endif
 #endif
     UNLOCK();