1 /* Siconos is a program dedicated to modeling, simulation and control
2  * of non smooth dynamical systems.
3  *
4  * Copyright 2021 INRIA.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17 */
18 
19 #ifndef TLSDEF_H
20 #define TLSDEF_H
21 
22 /*! \file tlsdef.h
23  *  \brief definition of thread local variable
24  */
25 
26 #if defined(__GNUC__)
27 #define DESTRUCTOR_ATTR __attribute__ ((destructor))
28 #define CONSTRUCTOR_ATTR __attribute__ ((constructor))
29 #else
30 #define DESTRUCTOR_ATTR
31 #define CONSTRUCTOR_ATTR
32 #endif
33 
34 
35 #if !defined(__cplusplus) || !defined(BUILD_AS_CPP)
36 
37   #ifdef SWIG
38     #define tlsvar
39 
40   #elif __STDC_VERSION__ >= 201112L && defined(__STDC_NO_THREADS__) && __STDC_NO_THREADS__ == 0
41     #include <threads.h>
42     #define tlsvar thread_local
43   #else
44 
45     #if defined(__GNUC__) || (defined(__ICC) && defined(__linux))
46       #define tlsvar __thread
47     #elif defined(__ICC) && defined(_WIN32)
48       #define tlsvar __declspec(thread)
49     #elif defined(SICONOS_ALLOW_GLOBAL)
50       #define tlsvar
51     #else
52       #error "Don't know how to create a thread-local variable"
53     #endif
54   #endif
55 
56 #else
57 
58   #ifdef SWIG
59     #define tlsvar
60 
61   #elif __cplusplus >= 201103L
62     #define tlsvar thread_local
63   #else
64     #if defined(__GNUC__) || (defined(__ICC) && defined(__linux))
65       #define tlsvar __thread
66     #elif defined(_MSC_VER) || (defined(__ICC) && defined(_WIN32))
67       #define tlsvar __declspec(thread)
68     #elif defined(SICONOS_ALLOW_GLOBAL)
69       #define tlsvar
70     #else
71       #error "Don't know how to create a thread-local variable"
72     #endif
73   #endif
74 
75 #endif
76 
77 #endif
78