[sgen] Evacuate from emptier blocks to fuller ones
[mono.git] / mono / utils / mono-tls.h
1 /*
2  * mono-tls.h: Low-level TLS support
3  *
4  * Author:
5  *      Rodrigo Kumpera (kumpera@gmail.com)
6  *
7  * Copyright 2011 Novell, Inc (http://www.novell.com)
8  * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
9  */
10
11 #ifndef __MONO_TLS_H__
12 #define __MONO_TLS_H__
13
14 #include <glib.h>
15
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;
31
32 #ifdef HOST_WIN32
33
34 #include <windows.h>
35
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
41
42 #else
43
44 #include <pthread.h>
45
46 #define MonoNativeTlsKey pthread_key_t
47 #define mono_native_tls_get_value pthread_getspecific
48
49 static inline int
50 mono_native_tls_alloc (MonoNativeTlsKey *key, void *destructor)
51 {
52         return pthread_key_create (key, (void (*)(void*)) destructor) == 0;
53 }
54
55 static inline void
56 mono_native_tls_free (MonoNativeTlsKey key)
57 {
58         pthread_key_delete (key);
59 }
60
61 static inline int
62 mono_native_tls_set_value (MonoNativeTlsKey key, gpointer value)
63 {
64         return !pthread_setspecific (key, value);
65 }
66
67 #endif /* HOST_WIN32 */
68
69 int mono_tls_key_get_offset (MonoTlsKey key);
70 void mono_tls_key_set_offset (MonoTlsKey key, int offset);
71
72 #endif /* __MONO_TLS_H__ */