Fix NET_2_0 build
[mono-project.git] / mono / utils / mono-tls.h
blob485aea76f3a0f3e13bad9b2fb19e579c8e96dc27
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 */
11 #ifndef __MONO_TLS_H__
12 #define __MONO_TLS_H__
14 #include <glib.h>
16 /* TLS entries used by the runtime */
17 typedef enum {
18 /* mono_thread_internal_current () */
19 TLS_KEY_THREAD = 0,
20 TLS_KEY_JIT_TLS = 1,
21 /* mono_domain_get () */
22 TLS_KEY_DOMAIN = 2,
23 TLS_KEY_LMF = 3,
24 TLS_KEY_SGEN_THREAD_INFO = 4,
25 TLS_KEY_SGEN_TLAB_NEXT_ADDR = 5,
26 TLS_KEY_SGEN_TLAB_TEMP_END = 6,
27 TLS_KEY_BOEHM_GC_THREAD = 7,
28 TLS_KEY_LMF_ADDR = 8,
29 TLS_KEY_NUM = 9
30 } MonoTlsKey;
32 #ifdef HOST_WIN32
34 #include <windows.h>
36 #define MonoNativeTlsKey DWORD
37 #define mono_native_tls_alloc(key,destructor) ((*(key) = TlsAlloc ()) != TLS_OUT_OF_INDEXES && destructor == NULL)
38 #define mono_native_tls_free TlsFree
39 #define mono_native_tls_set_value TlsSetValue
40 #define mono_native_tls_get_value TlsGetValue
42 #else
44 #include <pthread.h>
46 #define MonoNativeTlsKey pthread_key_t
47 #define mono_native_tls_get_value pthread_getspecific
49 static inline int
50 mono_native_tls_alloc (MonoNativeTlsKey *key, void *destructor)
52 return pthread_key_create (key, destructor) == 0;
55 static inline void
56 mono_native_tls_free (MonoNativeTlsKey key)
58 pthread_key_delete (key);
61 static inline int
62 mono_native_tls_set_value (MonoNativeTlsKey key, gpointer value)
64 return !pthread_setspecific (key, value);
67 #endif /* HOST_WIN32 */
69 int mono_tls_key_get_offset (MonoTlsKey key);
70 void mono_tls_key_set_offset (MonoTlsKey key, int offset);
72 #endif /* __MONO_TLS_H__ */