Merge pull request #156 from garuma/tpl-dataflow-tasks
[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  * (C) 2011 Novell, Inc
8  */
9
10 #ifndef __MONO_TLS_H__
11 #define __MONO_TLS_H__
12
13
14 #ifdef HOST_WIN32
15
16 #include <windows.h>
17
18 #define MonoNativeTlsKey DWORD
19 #define mono_native_tls_alloc(key,destructor) ((*(key) = TlsAlloc ()) != TLS_OUT_OF_INDEXES && destructor == NULL)
20 #define mono_native_tls_free TlsFree
21 #define mono_native_tls_set_value TlsSetValue
22 #define mono_native_tls_get_value TlsGetValue
23
24 #else
25
26 #include <pthread.h>
27
28 #define MonoNativeTlsKey pthread_key_t
29 #define mono_native_tls_get_value pthread_getspecific
30
31 static inline int
32 mono_native_tls_alloc (MonoNativeTlsKey *key, void *destructor)
33 {
34         return pthread_key_create (key, destructor) == 0;
35 }
36
37 static inline void
38 mono_native_tls_free (MonoNativeTlsKey key)
39 {
40         pthread_key_delete (key);
41 }
42
43 static inline int
44 mono_native_tls_set_value (MonoNativeTlsKey key, gpointer value)
45 {
46         return !pthread_setspecific (key, value);
47 }
48
49 #endif /* HOST_WIN32 */
50
51
52 #endif /* __MONO_TLS_H__ */