2005-03-29 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mono / os / gc_wrapper.h
index f32d42013af3a7a260422c7fd096ca0e20b5a0cf..3e68e2cbc11935e7042bcf0c797fed42eccb630a 100644 (file)
@@ -5,29 +5,54 @@
 
 #ifdef HAVE_BOEHM_GC
 
-#ifdef HAVE_GC_GC_H
-#include <gc/gc.h>
-#include <gc/gc_typed.h>
-#include <gc/gc_gcj.h>
-#include <gc/gc_mark.h>
-#else
+#      ifdef _MSC_VER
+#              include <winsock2.h>
+#      else
+               /* libgc specifies this on the command line,
+                * so we must define it ourselfs
+               */
+#              define GC_GCJ_SUPPORT
+#      endif
 
-#if defined(HAVE_GC_H) || defined(USE_INCLUDED_LIBGC)
-#include <gc.h>
-#include <gc_typed.h>
-#include <gc_gcj.h>
-#include <gc_mark.h>
-#else
-#error have boehm GC without headers, you probably need to install them by hand
-#endif
+       /*
+        * Local allocation is only beneficial if we have __thread
+        * We had to fix a bug with include order in libgc, so only do
+        * it if it is the included one.
+        */
+       
+#      if defined(HAVE_KW_THREAD) && defined(USE_INCLUDED_LIBGC)  
+#              define GC_REDIRECT_TO_LOCAL
+#      endif
 
+#      ifdef HAVE_GC_GC_H
+#              include <gc/gc.h>
+#              include <gc/gc_typed.h>
+#              include <gc/gc_mark.h>
+#              include <gc/gc_gcj.h>
+#      elif defined(HAVE_GC_H) || defined(USE_INCLUDED_LIBGC)
+#              include <gc.h>
+#              include <gc_typed.h>
+#              include <gc_mark.h>
+#              include <gc_gcj.h>
+#      else
+#              error have boehm GC without headers, you probably need to install them by hand
+#      endif
+       /* for some strange resion, they want one extra byte on the end */
+#      define MONO_GC_REGISTER_ROOT(x) \
+               GC_add_roots ((char*)&(x), (char*)&(x) + sizeof (x) + 1)
+       /* this needs to be called before ANY gc allocations. We can't use
+        * mono_gc_init here because we need to make allocations before that
+        * function is called 
+        */
+#      define MONO_GC_PRE_INIT() GC_init ()
+
+#if defined(PLATFORM_WIN32)
+#define CreateThread GC_CreateThread
 #endif
-/* for some strange resion, they want one extra byte on the end */
-#define MONO_GC_REGISTER_ROOT(x) \
-       GC_add_roots ((char*)&(x), (char*)&(x) + sizeof (x) + 1)
 
 #else
-
-#define MONO_GC_REGISTER_ROOT(x) /* nop */
+#      define MONO_GC_REGISTER_ROOT(x) /* nop */
+#      define MONO_GC_PRE_INIT()
 #endif
+
 #endif