Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef SG_SYSTEM_H
00010 #define SG_SYSTEM_H
00011
00012
00013
00014
00015 #ifdef HAVE_CONFIG_H
00016 #include <config.h>
00017 #endif
00018
00019
00020
00021
00022
00023 template <class T>
00024 inline void SG_UNUSED(const T&)
00025 {
00026 }
00027
00028
00029
00030 #ifndef NDEBUG
00031 #define SG_DEBUG_ONLY(x)
00032 #else
00033 #define SG_DEBUG_ONLY(x) SG_UNUSED(x)
00034 #endif
00035
00036
00037
00038
00039
00040
00041
00042 #if defined(__GNUC__) && ! defined(__ICC)
00043 #define SG_ATTR_ALWAYS_INLINE __attribute__((always_inline))
00044 #define SG_ATTR_NOINLINE __attribute__((noinline))
00045 #else
00046 #define SG_ATTR_NOINLINE
00047 #define SG_ATTR_ALWAYS_INLINE
00048 #endif
00049
00050 #if defined(__GNUC__) && ! defined(__ICC) && \
00051 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
00052 #define SG_ATTR_FLATTEN __attribute__((flatten))
00053 #else
00054 #define SG_ATTR_FLATTEN
00055 #endif
00056
00057
00058
00059 #include <sys/types.h>
00060 #if (BYTE_ORDER == BIG_ENDIAN)
00061 #define OTHER_BYTE_ORDER 0
00062 #else
00063 #define OTHER_BYTE_ORDER 1
00064 #endif
00065
00066
00067
00068
00069 class SgAssertionHandler
00070 {
00071 public:
00072
00073
00074 SgAssertionHandler();
00075
00076
00077
00078 virtual ~SgAssertionHandler();
00079
00080 virtual void Run() = 0;
00081 };
00082
00083 #ifndef NDEBUG
00084
00085
00086 void SgHandleAssertion(const char* expr, const char* file, int line);
00087
00088 #define SG_ASSERT(x) \
00089 do \
00090 { \
00091 if(! (x)) \
00092 ::SgHandleAssertion(#x, __FILE__, __LINE__); \
00093 } while (false)
00094 #else
00095 #define SG_ASSERT(x) (static_cast<void>(0))
00096 #endif
00097
00098 #define SG_ASSERTRANGE(i, from, to) SG_ASSERT(i >= from && i <= to)
00099
00100
00101
00102 #ifndef NDEBUG
00103 const bool SG_CHECK = true;
00104 const bool SG_HEAVYCHECK = SG_CHECK && true;
00105 #else
00106 const bool SG_CHECK = false;
00107 const bool SG_HEAVYCHECK = false;
00108 #endif
00109
00110
00111
00112 #if defined(WIN32) && defined(_MSC_VER)
00113
00114
00115
00116
00117 #define _HAS_CPP0X 0
00118
00119
00120
00121
00122
00123
00124 #pragma warning(4:4355)
00125
00126
00127
00128 #define _CRT_SECURE_NO_WARNINGS
00129 #define _SCL_SECURE_NO_WARNINGS
00130
00131 #endif // defined(WIN32) && defined(_MSC_VER)
00132
00133
00134
00135 #ifdef __MINGW32__
00136
00137 #define WIN32 1
00138
00139
00140 #define WINVER 0x0500
00141 #define _WIN32_WINNT 0x0500
00142
00143 #endif // __MINGW32__
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 void SgSetUserAbort(bool aborted);
00155
00156
00157
00158 bool SgUserAbort();
00159
00160
00161
00162 inline void SgSynchronizeThreadMemory()
00163 {
00164 #ifdef ENABLE_CACHE_SYNC
00165
00166 #ifdef HAVE_SYNC_SYNCHRONIZE
00167 __sync_synchronize();
00168 #else
00169 #error "Explicit cache synchronization requires __sync_synchronize() builtin"
00170 #endif
00171
00172 #endif
00173 }
00174
00175
00176
00177 #endif // SG_SYSTEM_H