2 * mono-tls.h: Low-level TLS support
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__
18 /* TLS entries used by the runtime */
20 /* mono_thread_internal_current () */
23 /* mono_domain_get () */
26 TLS_KEY_SGEN_THREAD_INFO
= 4,
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
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
56 #define MonoNativeTlsKey pthread_key_t
57 #define mono_native_tls_get_value pthread_getspecific
60 mono_native_tls_alloc (MonoNativeTlsKey
*key
, void *destructor
)
62 return pthread_key_create (key
, (void (*)(void*)) destructor
) == 0;
66 mono_native_tls_free (MonoNativeTlsKey key
)
68 pthread_key_delete (key
);
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__ */