b4ea3770ad2af85b15e3a08af7de2fc77da7a5da
[mono.git] / mono / utils / gc_wrapper.h
1 /* 
2  * Copyright 2004-2011 Novell, Inc (http://www.novell.com)
3  * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
4  */
5 #ifndef __MONO_OS_GC_WRAPPER_H__
6 #define __MONO_OS_GC_WRAPPER_H__
7
8 #include <config.h>
9 #include <stdlib.h>
10
11 #ifdef HAVE_BOEHM_GC
12
13 #       ifdef _MSC_VER
14 #               include <winsock2.h>
15 #       else
16                 /* libgc specifies this on the command line,
17                  * so we must define it ourselfs
18                 */
19 #               define GC_GCJ_SUPPORT
20 #       endif
21
22         /*
23          * Local allocation is only beneficial if we have __thread
24          * We had to fix a bug with include order in libgc, so only do
25          * it if it is the included one.
26          */
27         
28 #       if defined(HAVE_KW_THREAD) && defined(USE_INCLUDED_LIBGC) && !defined(__powerpc__)
29         /* The local alloc stuff is in pthread_support.c, but solaris uses solaris_threads.c */
30         /* It is also disabled on solaris/x86 by libgc/configure.in */
31         /* 
32                  * ARM has no definition for some atomic functions in gc_locks.h and
33                  * support is also disabled in libgc/configure.in.
34                  */
35 #       if !defined(__sparc__) && !defined(__sun) && !defined(__arm__) && !defined(__mips__)
36 #                   define GC_REDIRECT_TO_LOCAL
37 #       endif
38 #       endif
39
40 #       ifdef HAVE_GC_GC_H
41 #               include <gc/gc.h>
42 #               include <gc/gc_typed.h>
43 #               include <gc/gc_mark.h>
44 #               include <gc/gc_gcj.h>
45 #       elif defined(HAVE_GC_H) || defined(USE_INCLUDED_LIBGC)
46 #               include <gc.h>
47 #               include <gc_typed.h>
48 #               include <gc_mark.h>
49 #               include <gc_gcj.h>
50 #       else
51 #               error have boehm GC without headers, you probably need to install them by hand
52 #       endif
53
54 #if defined(HOST_WIN32)
55 #define CreateThread GC_CreateThread
56 #endif
57
58 #elif defined(HAVE_SGEN_GC)
59
60 #else /* not Boehm and not sgen GC */
61 #endif
62
63 #if !defined(HOST_WIN32)
64
65 /*
66  * Both Boehm and SGEN needs to intercept some thread operations. So instead of the
67  * pthread_... calls, runtime code should call these wrappers.
68  */
69
70 /* pthread function wrappers */
71 #include <pthread.h>
72 #include <signal.h>
73
74 int mono_gc_pthread_create (pthread_t *new_thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
75 int mono_gc_pthread_join (pthread_t thread, void **retval);
76 int mono_gc_pthread_detach (pthread_t thread);
77 void mono_gc_pthread_exit (void *retval) G_GNUC_NORETURN;
78
79 #endif
80
81 #endif