itom  4.1.0
commonGlobal.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 *********************************************************************** */
27 
28 #ifndef COMMONGLOBAL_H
29 #define COMMONGLOBAL_H
30 
31 #if (defined ITOMLIBS_SHARED && ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
32 
33  #ifndef ITOMCOMMON_EXPORT
34 
35  /* Borland/Microsoft */
36  #if defined(_MSC_VER) || defined(__BORLANDC__)
37  #if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
38  #else
39  #ifdef ITOMCOMMON_DLL
40  #define ITOMCOMMON_EXPORT __export
41  #else
42  #define ITOMCOMMON_EXPORT /*__import */ /* doesn't exist AFAIK in VC++ */
43  #endif /* Exists in Borland C++ for
44  C++ classes (== huge) */
45  #endif
46  #endif
47 
48  #ifndef ITOMCOMMON_EXPORT //ITOMCOMMON_EXPORT has not be defined yet
49  #ifdef ITOMCOMMON_DLL
50  #define ITOMCOMMON_EXPORT __declspec(dllexport)
51  #else
52  #define ITOMCOMMON_EXPORT __declspec(dllimport)
53  #endif
54  #endif
55 
56  #endif //ITOMCOMMON_EXPORT
57 
58 #endif //windows
59 
60 #ifndef ITOMCOMMON_EXPORT
61  #define ITOMCOMMON_EXPORT
62 #endif
63 
64 
65 #if (defined ITOMLIBS_SHARED && ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
66 
67  #ifndef ITOMCOMMONQT_EXPORT
68 
69  /* Borland/Microsoft */
70  #if defined(_MSC_VER) || defined(__BORLANDC__)
71  #if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
72  #else
73  #ifdef ITOMCOMMONQT_DLL
74  #define ITOMCOMMONQT_EXPORT __export
75  #else
76  #define ITOMCOMMONQT_EXPORT /*__import */ /* doesn't exist AFAIK in VC++ */
77  #endif /* Exists in Borland C++ for
78  C++ classes (== huge) */
79  #endif
80  #endif
81 
82  #ifndef ITOMCOMMONQT_EXPORT //ITOMCOMMONQT_EXPORT has not be defined yet
83  #ifdef ITOMCOMMONQT_DLL
84  #define ITOMCOMMONQT_EXPORT __declspec(dllexport)
85  #else
86  #define ITOMCOMMONQT_EXPORT __declspec(dllimport)
87  #endif
88  #endif
89 
90  #endif //ITOMCOMMONQT_EXPORT
91 
92 #endif //windows
93 
94 #ifndef ITOMCOMMONQT_EXPORT
95  #define ITOMCOMMONQT_EXPORT
96 #endif
97 
99  #ifdef __GNUC__
100 
101  #if __GNUC__*10 + __GNUC_MINOR__ >= 42
102 
103  #if !defined WIN32 && (defined __i486__ || defined __i586__ || \
104  defined __i686__ || defined __MMX__ || defined __SSE__ || defined __ppc__)
105  #define ITOM_XADD __sync_fetch_and_add
106  #else
107  #include <ext/atomicity.h>
108  #define ITOM_XADD __gnu_cxx::__exchange_and_add
109  #endif
110 
111  #else
112  #include <bits/atomicity.h>
113  #if __GNUC__*10 + __GNUC_MINOR__ >= 34
114  #define ITOM_XADD __gnu_cxx::__exchange_and_add
115  #else
116  #define ITOM_XADD __exchange_and_add
117  #endif
118  #endif
119 
120  #elif (defined WIN32 || defined _WIN32)
121  #include <intrin.h>
122  #define ITOM_XADD(addr,delta) _InterlockedExchangeAdd((long volatile*)(addr), (delta))
123  #else
124  template<typename _Tp> static inline _Tp ITOM_XADD(_Tp* addr, _Tp delta)
125  { int tmp = *addr; *addr += delta; return tmp; }
126  #endif
127 
128  #define ITOM_INCREF(intvar) ITOM_XADD(intvar,1)
129  #define ITOM_DECREF(intvar) ITOM_XADD(intvar,-1)
130 
131 #endif
132