2 * Copyright 2001-2003 Ximian, Inc
3 * Copyright 2003-2010 Novell, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #ifndef __MONO_SGENGC_H__
25 #define __MONO_SGENGC_H__
32 #include <mono/utils/mono-compiler.h>
33 #include <mono/metadata/class-internals.h>
35 #define THREAD_HASH_SIZE 11
37 #define ARCH_THREAD_TYPE pthread_t
38 #define ARCH_GET_THREAD pthread_self
39 #define ARCH_THREAD_EQUALS(a,b) pthread_equal (a, b)
41 #if SIZEOF_VOID_P == 4
42 typedef guint32 mword;
44 typedef guint64 mword;
47 /* for use with write barriers */
48 typedef struct _RememberedSet RememberedSet;
49 struct _RememberedSet {
53 mword data [MONO_ZERO_LEN_ARRAY];
56 /* eventually share with MonoThread? */
57 typedef struct _SgenThreadInfo SgenThreadInfo;
59 struct _SgenThreadInfo {
62 unsigned int stop_count; /* to catch duplicate signals */
65 volatile int in_critical_region;
68 void *stack_start_limit;
69 char **tlab_next_addr;
70 char **tlab_start_addr;
71 char **tlab_temp_end_addr;
72 char **tlab_real_end_addr;
73 gpointer **store_remset_buffer_addr;
74 long *store_remset_buffer_index_addr;
75 RememberedSet *remset;
76 gpointer runtime_data;
77 gpointer stopped_ip; /* only valid if the thread is stopped */
78 MonoDomain *stopped_domain; /* ditto */
79 gpointer *stopped_regs; /* ditto */
80 #ifndef HAVE_KW_THREAD
85 gpointer *store_remset_buffer;
86 long store_remset_buffer_index;
91 static int suspend_signal_num = SIGXFSZ;
93 static int suspend_signal_num = SIGPWR;
95 static int restart_signal_num = SIGXCPU;
98 * Recursion is not allowed for the thread lock.
100 #define LOCK_DECLARE(name) pthread_mutex_t name = PTHREAD_MUTEX_INITIALIZER
101 #define LOCK_INIT(name)
102 #define LOCK_GC pthread_mutex_lock (&gc_mutex)
103 #define UNLOCK_GC pthread_mutex_unlock (&gc_mutex)
104 #define LOCK_INTERRUPTION pthread_mutex_lock (&interruption_mutex)
105 #define UNLOCK_INTERRUPTION pthread_mutex_unlock (&interruption_mutex)
107 /* non-pthread will need to provide their own version of start/stop */
108 #define USE_SIGNAL_BASED_START_STOP_WORLD 1
109 /* we intercept pthread_create calls to know which threads exist */
110 #define USE_PTHREAD_INTERCEPT 1
112 #define MAX_DEBUG_LEVEL 2
113 #define DEBUG(level,a) do {if (G_UNLIKELY ((level) <= MAX_DEBUG_LEVEL && (level) <= gc_debug_level)) a;} while (0)
115 int mono_sgen_thread_handshake (int signum) MONO_INTERNAL;
116 SgenThreadInfo* mono_sgen_thread_info_lookup (ARCH_THREAD_TYPE id) MONO_INTERNAL;
117 SgenThreadInfo** mono_sgen_get_thread_table (void) MONO_INTERNAL;
118 void mono_sgen_wait_for_suspend_ack (int count) MONO_INTERNAL;
120 gboolean mono_sgen_is_worker_thread (pthread_t thread) MONO_INTERNAL;
122 #endif /* __MONO_SGENGC_H__ */