* PropertyDescriptorCollectionTests.cs: Allow tests for pass on MS.
[mono.git] / libgc / pthread_support.c
index 7f3c31efd81c06065271a478ff2d141af075f6ff..6306f2cd0ceb244d445e0701e0d8ca2ef01bf71b 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
 
 # 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,11 +191,22 @@ static
 GC_key_t GC_thread_key;
 
 #ifdef USE_COMPILER_TLS
-static __thread MONO_TLS_FAST void* GC_thread_tls;
+/*
+ * gcc errors out with /tmp/ccdPMFuq.s:2994: Error: symbol `.LTLS4' is already defined
+ * if the static is removed on ppc.
+ */
+#if defined(__ppc__) || defined(__powerpc__)
+static
+#endif
+__thread MONO_TLS_FAST void* GC_thread_tls;
 #endif
 
 static GC_bool keys_initialized;
 
+#ifdef MONO_DEBUGGER_SUPPORTED
+#include "include/libgc-mono-debugger.h"
+#endif
+
 /* Recover the contents of the freelist array fl into the global one gfl.*/
 /* Note that the indexing scheme differs, in that gfl has finer size   */
 /* resolution, even if not all entries are used.                       */
@@ -663,7 +679,8 @@ GC_thread GC_new_thread(pthread_t id)
        result = &first_thread;
        first_thread_used = TRUE;
     } else {
-       result = calloc (1, sizeof (struct GC_Thread_Rep));
+        result = (struct GC_Thread_Rep *)
+                GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL);
     }
     if (result == 0) return(0);
     result -> id = id;
@@ -691,9 +708,16 @@ void GC_delete_thread(pthread_t id)
     } else {
         prev -> next = p -> next;
     }
+#ifdef MONO_DEBUGGER_SUPPORTED
     if (gc_thread_vtable && gc_thread_vtable->thread_exited)
        gc_thread_vtable->thread_exited (id, &p->stop_info.stack_ptr);
-    free(p);
+#endif
+       
+#ifdef GC_DARWIN_THREADS
+       mach_port_deallocate(mach_task_self(), p->stop_info.mach_thread);
+#endif
+       
+    GC_INTERNAL_FREE(p);
 }
 
 /* If a thread has been joined, but we have not yet            */
@@ -715,7 +739,12 @@ void GC_delete_gc_thread(pthread_t id, GC_thread gc_id)
     } else {
         prev -> next = p -> next;
     }
-    free(p);
+       
+#ifdef GC_DARWIN_THREADS
+       mach_port_deallocate(mach_task_self(), p->stop_info.mach_thread);
+#endif
+       
+    GC_INTERNAL_FREE(p);
 }
 
 /* Return a GC_thread corresponding to a given pthread_t.      */
@@ -768,11 +797,12 @@ void GC_remove_all_threads_but_me(void)
              GC_destroy_thread_local(p);
            }
 #        endif /* THREAD_LOCAL_ALLOC */
-           if (p != &first_thread) free(p);
+           if (p != &first_thread) GC_INTERNAL_FREE(p);
        }
       }
       GC_threads[hv] = me;
     }
+    GC_INTERNAL_FREE(p);
 }
 #endif /* HANDLE_FORK */
 
@@ -970,8 +1000,10 @@ void GC_thr_init()
          t -> stop_info.stack_ptr = (ptr_t)(&dummy);
 #     endif
       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);
+#endif
 
     GC_stop_init();
 
@@ -993,7 +1025,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);
@@ -1277,8 +1309,10 @@ void * GC_start_routine_head(void * arg, void *base_addr,
       /* This is also < 100% convincing.  We should also read this     */
       /* from /proc, but the hook to do so isn't there yet.            */
 #   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);
+#endif
     UNLOCK();
 
     if (start) *start = si -> start_routine;
@@ -1361,7 +1395,8 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread,
     /* responsibility.                                                 */
 
     LOCK();
-    si = calloc (1, sizeof (struct start_info));
+    si = (struct start_info *)GC_INTERNAL_MALLOC(sizeof(struct start_info),
+                                                NORMAL);
     UNLOCK();
     if (!parallel_initialized) GC_init_parallel();
     if (0 == si) return(ENOMEM);
@@ -1421,7 +1456,7 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread,
     }
     sem_destroy(&(si -> registered));
     LOCK();
-    free(si);
+    GC_INTERNAL_FREE(si);
     UNLOCK();
 
     return(result);