* Makefile: Consolidate more lists and make some
[mono.git] / mono / os / gc_wrapper.h
1 #ifndef __MONO_OS_GC_WRAPPER_H__
2 #define __MONO_OS_GC_WRAPPER_H__
3
4 #include <config.h>
5
6 #ifdef HAVE_BOEHM_GC
7
8 #       ifdef _MSC_VER
9 #               include <winsock2.h>
10 #       else
11                 /* libgc specifies this on the command line,
12                  * so we must define it ourselfs
13                 */
14 #               define GC_GCJ_SUPPORT
15 #       endif
16
17         /*
18          * Local allocation is only beneficial if we have __thread
19          * We had to fix a bug with include order in libgc, so only do
20          * it if it is the included one.
21          */
22         
23 #       if defined(HAVE_KW_THREAD) && defined(USE_INCLUDED_LIBGC) && !defined(__powerpc__)
24         /* The local alloc stuff is in pthread_support.c, but solaris uses solaris_threads.c */
25         /* It is also disabled on solaris/x86 by libgc/configure.in */
26 #       if !defined(__sparc__) && !defined(__sun)
27 #                   define GC_REDIRECT_TO_LOCAL
28 #       endif
29 #       endif
30
31 #       ifdef HAVE_GC_GC_H
32 #               include <gc/gc.h>
33 #               include <gc/gc_typed.h>
34 #               include <gc/gc_mark.h>
35 #               include <gc/gc_gcj.h>
36 #       elif defined(HAVE_GC_H) || defined(USE_INCLUDED_LIBGC)
37 #               include <gc.h>
38 #               include <gc_typed.h>
39 #               include <gc_mark.h>
40 #               include <gc_gcj.h>
41 #       else
42 #               error have boehm GC without headers, you probably need to install them by hand
43 #       endif
44         /* for some strange resion, they want one extra byte on the end */
45 #       define MONO_GC_REGISTER_ROOT(x) \
46                 GC_add_roots ((char*)&(x), (char*)&(x) + sizeof (x) + 1)
47         /* this needs to be called before ANY gc allocations. We can't use
48          * mono_gc_init here because we need to make allocations before that
49          * function is called 
50          */
51 #       define MONO_GC_PRE_INIT() GC_init ()
52
53 #if defined(PLATFORM_WIN32)
54 #define CreateThread GC_CreateThread
55 #endif
56
57 #elif defined(HAVE_SGEN_GC)
58
59 #if defined(PLATFORM_WIN32)
60 #define CreateThread mono_gc_CreateThread
61 #else
62 /* pthread function wrappers */
63 #include <pthread.h>
64 #include <signal.h>
65
66 int mono_gc_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
67 int mono_gc_pthread_join (pthread_t thread, void **retval);
68 int mono_gc_pthread_detach (pthread_t thread);
69
70 #define pthread_create mono_gc_pthread_create
71 #define pthread_join mono_gc_pthread_join
72 #define pthread_detach mono_gc_pthread_detach
73
74 #endif
75
76 extern int
77 mono_gc_register_root (char *start, size_t size, void *descr);
78 extern void mono_gc_base_init (void);
79
80 #       define MONO_GC_REGISTER_ROOT(x) mono_gc_register_root (&(x), sizeof(x), NULL)
81 #       define MONO_GC_PRE_INIT() mono_gc_base_init ()
82
83 #else /* not Boehm and not sgen GC */
84 #       define MONO_GC_REGISTER_ROOT(x) /* nop */
85 #       define MONO_GC_PRE_INIT()
86 #endif
87
88 #endif