[sgen] Add parallel copying infrastructure
[mono-project.git] / mono / utils / mono-tls.h
bloba3751ea6e38b7ee2bbc60aaa1390f35d1eb2b88d
1 /*
2 * mono-tls.h: Low-level TLS support
4 * Author:
5 * Rodrigo Kumpera (kumpera@gmail.com)
7 * Copyright 2011 Novell, Inc (http://www.novell.com)
8 * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
12 #ifndef __MONO_TLS_H__
13 #define __MONO_TLS_H__
15 #include <config.h>
16 #include <glib.h>
18 /* TLS entries used by the runtime */
19 typedef enum {
20 /* mono_thread_internal_current () */
21 TLS_KEY_THREAD = 0,
22 TLS_KEY_JIT_TLS = 1,
23 /* mono_domain_get () */
24 TLS_KEY_DOMAIN = 2,
25 TLS_KEY_LMF = 3,
26 TLS_KEY_SGEN_THREAD_INFO = 4,
27 TLS_KEY_LMF_ADDR = 5,
28 TLS_KEY_NUM = 6
29 } MonoTlsKey;
31 #ifdef HAVE_KW_THREAD
32 #define USE_KW_THREAD
33 #endif
35 #if defined(USE_KW_THREAD)
36 #define HAVE_GET_TLS_ADDR
37 #elif defined(TARGET_MACH) && (defined(TARGET_X86) || defined(TARGET_AMD64))
38 /* mono_mach_get_tls_address_from_thread is untested for arm/arm64 */
39 #define HAVE_GET_TLS_ADDR
40 #endif
42 #ifdef HOST_WIN32
44 #include <windows.h>
46 #define MonoNativeTlsKey DWORD
47 #define mono_native_tls_alloc(key,destructor) ((*(key) = TlsAlloc ()) != TLS_OUT_OF_INDEXES && destructor == NULL)
48 #define mono_native_tls_free TlsFree
49 #define mono_native_tls_set_value TlsSetValue
50 #define mono_native_tls_get_value TlsGetValue
52 #else
54 #include <pthread.h>
56 #define MonoNativeTlsKey pthread_key_t
57 #define mono_native_tls_get_value pthread_getspecific
59 static inline int
60 mono_native_tls_alloc (MonoNativeTlsKey *key, void *destructor)
62 return pthread_key_create (key, (void (*)(void*)) destructor) == 0;
65 static inline void
66 mono_native_tls_free (MonoNativeTlsKey key)
68 pthread_key_delete (key);
71 static inline int
72 mono_native_tls_set_value (MonoNativeTlsKey key, gpointer value)
74 return !pthread_setspecific (key, value);
77 #endif /* HOST_WIN32 */
79 void mono_tls_init_gc_keys (void);
80 void mono_tls_init_runtime_keys (void);
81 void mono_tls_free_keys (void);
82 gint32 mono_tls_get_tls_offset (MonoTlsKey key);
83 gpointer mono_tls_get_tls_getter (MonoTlsKey key, gboolean name);
84 gpointer mono_tls_get_tls_setter (MonoTlsKey key, gboolean name);
85 gpointer mono_tls_get_tls_addr (MonoTlsKey key);
87 gpointer mono_tls_get_thread (void);
88 gpointer mono_tls_get_jit_tls (void);
89 gpointer mono_tls_get_domain (void);
90 gpointer mono_tls_get_lmf (void);
91 gpointer mono_tls_get_sgen_thread_info (void);
92 gpointer mono_tls_get_lmf_addr (void);
94 void mono_tls_set_thread (gpointer value);
95 void mono_tls_set_jit_tls (gpointer value);
96 void mono_tls_set_domain (gpointer value);
97 void mono_tls_set_lmf (gpointer value);
98 void mono_tls_set_sgen_thread_info (gpointer value);
99 void mono_tls_set_lmf_addr (gpointer value);
101 #endif /* __MONO_TLS_H__ */