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